Don't unconditionally set the hostname in cloud-init

We have seen some bare base images failing when hostnamectl is
being called during cloud-init. nova is setting a proper hostname
value in meta_data.json which cloud-init is using so make the
hostname setting optional if it is already correct.

Change-Id: I6920895532f29211b35f46b47d4160762b51dcd5
This commit is contained in:
Rob Crittenden 2017-08-25 14:08:36 -04:00
parent 8e78935e25
commit c873779708
1 changed files with 1 additions and 1 deletions

View File

@ -1 +1 @@
{"cloud-init": "#cloud-config\npackages:\n - python-simplejson\n - ipa-client\n - ipa-admintools\n - openldap-clients\nwrite_files:\n - content: |\n #!/bin/sh\n \n # Get the instance hostname out of the metadata\n #data=`curl http://169.254.169.254/openstack/latest/meta_data.json 2>/dev/null`\n sleep $[ ( $RANDOM % 10 ) + 1 ]s\n data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`\n if [[ $? != 0 ]] ; then\n echo \"Unable to retrieve metadata\"\n exit 1\n fi\n \n fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"hostname\", \"\")'`\n \n if [ -z \"$fqdn\" ]; then\n echo \"Unable to determine hostname\"\n exit 1\n fi\n \n otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"ipaotp\", \"\")'`\n\n # run ipa-client-install\n ipa-client-install -U -w $otp --hostname $fqdn\n path: /root/setup-ipa-client.sh\n permissions: '0700'\n owner: root:root\nruncmd:\n- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1"}
{"cloud-init": "#cloud-config\npackages:\n - python-simplejson\n - ipa-client\n - ipa-admintools\n - openldap-clients\n - hostname\nwrite_files:\n - content: |\n #!/bin/sh\n \n # Get the instance hostname out of the metadata\n #data=`curl http://169.254.169.254/openstack/latest/meta_data.json 2>/dev/null`\n sleep $[ ( $RANDOM % 10 ) + 1 ]s\n data=`curl -s http://169.254.169.254/openstack/2016-10-06/vendor_data2.json 2>/dev/null`\n if [[ $? != 0 ]] ; then\n echo \"Unable to retrieve metadata\"\n exit 1\n fi\n \n fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"hostname\", \"\")'`\n \n if [ -z \"$fqdn\" ]; then\n echo \"Unable to determine hostname\"\n exit 1\n fi\n \n otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get(\"join\", {}).get(\"ipaotp\", \"\")'`\n\n hostname=`/bin/hostname -f`\n\n # run ipa-client-install\n OPTS=\"-U -w $otp\"\n if [ $hostname != $fqdn ]; then\n OPTS=\"$OPTS --hostname $fqdn\"\n fi\n ipa-client-install $OPTS\n path: /root/setup-ipa-client.sh\n permissions: '0700'\n owner: root:root\nruncmd:\n- sh -x /root/setup-ipa-client.sh > /var/log/setup-ipa-client.log 2>&1"}