We are trying an automation of vmware vsphere guest os provisioning using puppet and facing some issues while running first boot script
Module code (Trimmed for best reading)
if $newip != '' {
notify { "Creating VM (${hostname})": }
vsphere_vm { "/${vm['datacenter']}/vm/${hostname}":
ensure => present,
cpus => 2,
memory => 512,
resource_pool => $vm['resource_pool'],
source => "${ibvs::templates[$vm['template']]['path']}",
extra_config => {
'guestinfo.infoblox.ipaddress' => $newip,
'guestinfo.infoblox.hostname' => $hostname,
'guestinfo.puppet.firstrun' => inline_epp($epp_template, {
'hostname' => $hostname,
'ipaddress' => "${newip}",
'puppet' => $ibvs::puppet,
}),
},
Below is the hiera data for vm provisioning
ibvs::vms:
'vzfleetpuppet.test.net':
ensure: present
datacenter: 'US'
template: puppettest
resource_pool: US-NORTH
interface: ens192
network: '10.254.8.0/23'
infoblox_network_view: test
infoblox_dns_view: Internal
infoblox_zone_auth: test.net
gateway: 10.254.8.1
dns:
- 10.223.106.250
- 10.246.107.110
puppet_psk: PSK_UNSET
puppet_role: role::generic
We are using infoblox to fetch free ip from the resource pool/Network and storing that in the variable newip . Once the vm is provisioned, the below first boot script will be executed
ibvs::templates:
puppettest:
path: "/Atlanta/vm/Template/puppettest"
firstboot_script: |
#!/bin/bash
# Check completion flag to see if we've already run
TEST=`vmtoolsd --cmd "info-get guestinfo.puppet.firstruncomplete"`
if [[ "${TEST}" != "true" ]]; then
# Hostname Configuration
hostnamectl set-hostname <%= $hostname %>
# Network IP Settings
nmcli connection modify <%= $vm['interface'] %> IPv4.address <%= $ipaddress %>
nmcli connection modify <%= $vm['interface'] %> IPv4.gateway <%= $vm['gateway'] %>
nmcli connection modify <%= $vm['interface'] %> IPv4.dns "<%= $vm['dns'] %>"
nmcli connection modify <%= $vm['interface'] %> IPv4.method manual
nmcli connection down <%= $vm['interface'] %> && nmcli connection up <%= $vm['interface'] %>
# Puppet Setup
curl -k https://<%= $puppet['server'] %>:8140/packages/current/install.bash | sudo bash -s \
agent:certname=<%= $hostname %> \
custom_attributes:challengePassword=<%= $vm['puppet_psk'] %> \
extension_requests:pp_role=<%= $vm['puppet_role'] %>
# Set completion flag so we don't run again
vmtoolsd --cmd "info-set guestinfo.puppet.firstruncomplete true"
fi
So as part of execution vm successfully created but we were not able to login since the network interface was not setup which suppose to be setup by first boot script
We are seeing the below information in vcenter /monitor/events tab (showing deleted in the end)
Reconfigured vzfleetpuppet.test.net on xxxx04si.test.net in US-NORTH . Modified: config.hardware.memoryMB: 2048 -> 512; config.extraConfig("viv.moid").value: "70f17107-45fc-48dd-a7f9-e4670f5ce07a:vm-1057259:7hPql31NJ8t7wPYQrZ+agcJErS2xwXYD8LbqWe2QVtI=" -> "70f17107-45fc-48dd-a7f9-e4670f5ce07a:vm-1057809:9Tdo/OLA/q9Lti41CWq84dikPfjjuFegnuJ47PevoIU="; Added: config.extraConfig("guestinfo.puppet.firstrun"): (key = "guestinfo.puppet.firstrun", value = "#!/bin/bash # Check completion flag to see if we've already run TEST=`vmtoolsd --cmd "info-get guestinfo.puppet.firstruncomplete"` if (( "$(TEST)" != "true" )); then # Hostname Configuration hostnamectl set-hostname vzfleetpuppet.test.net # Network IP Settings nmcli connection modify ens192 IPv4.address 10.254.8.32 nmcli connection modify ens192 IPv4.gateway 10.254.8.1 nmcli connection modify ens192 IPv4.dns "(10.223.106.250, 10.246.107.110)" nmcli connection modify ens192 IPv4.method manual nmcli connection down ens192 && nmcli connection up ens192 # Puppet Setup curl -k https://xxxxxx500c.test.net:8140/packages/current/install.bash | sudo bash -s \ agent:certname=vzfleetpuppet.test.net \ custom_attributes:challengePassword=PSK_UNSET \ extension_requests:pp_role=role::generic # Set completion flag so we don't run again vmtoolsd --cmd "info-set guestinfo.puppet.firstruncomplete true" fi "); config.extraConfig("guestinfo.infoblox.hostname"): (key = "guestinfo.infoblox.hostname", value = "vzfleetpuppet.test.net"); config.extraConfig("guestinfo.infoblox.ipaddress"): (key = "guestinfo.infoblox.ipaddress", value = "10.254.8.32"); Deleted:
we tried to find the log where the first boot script will be written by searching find with grep the pattern 'hostnamectl' but no luck. So seems like first boot script was not executed. So we are looking for how to troubleshoot this first boot script execution issue