We been trying to modify the cloud-init configuration for Portal EE 4.0 to assign a static IP on first boot. Each attempt that has been successful in updating the IP address has resulted in blocking the remaining cloud-init scripts and, as a result, does not create any users. Is there a way to configure a static IP that doesn't break the cloud-init config? Below is a sample config of what is placed in the meta-data. Looks like version Cloud-init 0.7.5 is in use here. The internet has similar stories regarding Ubuntu and upstart, but don't seem to apply 1 to 1 to this Centos 7.2 image. Any thoughts or assistance would be appreciated.
instance-id: iid-local01network-interfaces: | iface eth0 inet static address 10.10.10.2 network 10.10.10.0 netmask 255.255.255.0 broadcast 10.0.0.255 gateway 10.10.10.1hostname: myhostname
Append the following scripts in the “bootcmd:” section of “user-data” file.
- set -x; echo 'user-data/bootcmd:'
- set -x; sed -i -e 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0
- set -x; echo 'IPADDR=18.104.22.168' >> /etc/sysconfig/network-scripts/ifcfg-eth0
- set -x; echo 'GATEWAY=22.214.171.124' >> /etc/sysconfig/network-scripts/ifcfg-eth0
- set -x; echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
- set -x; echo 'ONBOOT="yes"' >> /etc/sysconfig/network-scripts/ifcfg-eth0
- set -x; echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-eth0
This works well, but take into account the bootcmd section is run each time the vm is started from the cloudinit iso. As a result of this the echo commands will be appended for each reboot with the iso attached, creating duplicate lines. If moved to the runcmd section it will be run only the first time.