Last active
September 29, 2020 12:16
-
-
Save janeczku/efd90654c7780f0de9ec11fcaa62a921 to your computer and use it in GitHub Desktop.
Cloud Init to use vSphere Network Protocol Profile for IP assignment on CentOS/RHEL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
write_files: | |
- path: /network-init.sh | |
content: | | |
#!/bin/bash | |
# Gateway 10.164.20.1 | |
# 10.164.20.x/24 | |
vmtoolsd --cmd 'info-get guestinfo.ovfEnv' > /tmp/ovfenv | |
IPAddress=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.address" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv) | |
SubnetMask=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.netmask" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv) | |
Gateway=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.route.0.gateway" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv) | |
DNS=$(sed -n 's/.*Property oe:key="guestinfo.dns.servers" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv) | |
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF | |
# default via $Gateway dev eth0 # if not set in /etc/sysconfig/network | |
BOOTPROTO=none | |
ONBOOT=yes | |
TYPE=Ethernet | |
USERCTL=no | |
DEVICE=eth0 | |
IPADDR=$IPAddress | |
NETMASK=255.255.255.0 | |
# /etc/sysconfig/network | |
GATEWAY=$Gateway | |
DNS1=8.8.8.8 | |
EOF | |
sudo systemctl restart network | |
runcmd: | |
- bash /network-init.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment