I managed to successfully provision CentOS 7.5 hosts from VMware templates on Foreman 1.19 using UserData and CloudInit plugin. However the stock puppet_setup_cloudinit provisioning template doesn’t seem to want to enable the puppet agent service after the cloudinit is ran. Previewing the output of the snippet shows the following.
if [ -f /usr/bin/dnf ]; then
dnf -y install puppet-agent
else
yum -t -y install puppet-agent
fi
/opt/puppetlabs/bin/puppet agent --config /etc/puppetlabs/puppet/puppet.conf --onetime --server foreman.dotslash.io --no-daemonize
Which suggests that it is skipping the block in the snippet altogether which I am not understanding. The os_family should already ‘Redhat’ and the os_major version is 7 which is greater than 6.
<% if os_family == 'Redhat' -%>
<% if os_major > 6 -%>
puppet_unit=puppet
/usr/bin/systemctl list-unit-files | grep -q puppetagent && puppet_unit=puppetagent
/usr/bin/systemctl enable ${puppet_unit}
<% else -%>
/sbin/chkconfig --level 345 puppet on
<% end -%>
<% end -%>
Go to the host in foreman and view the generated template. Does it look as expected there? If you run the commands in the generated template do they produce the desired results?
Did some additional investigation, and it seems like using offending block is this. Removing it allowed the subsequent conditionals for os_family == ‘Redhat’ to be preserved. However, the very last line where it calls puppet to start the agent service still does not appear until the <% end -%> tag is moved.
Offending block
<% elsif os_family == 'Suse' -%>
<% if host_param_true?('enable-puppetlabs-pc1-repo') || host_param_true?('enable-puppetlabs-puppet5-repo') -%>
rpmkeys --import http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
rpmkeys --import http://yum.puppetlabs.com/RPM-GPG-KEY-puppet
<% end -%>
<% if @host.provision_method == 'image' -%>
/usr/bin/zypper -n install <%= linux_package %>
<% end -%>