Skip to content

Instantly share code, notes, and snippets.

@timogoebel
Created April 26, 2018 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timogoebel/959deecff4f8ca8bcdd5fc9f95cbc8e3 to your computer and use it in GitHub Desktop.
Save timogoebel/959deecff4f8ca8bcdd5fc9f95cbc8e3 to your computer and use it in GitHub Desktop.
vSphere Templates for Foreman & cloud-init with the foreman_userdata plugin
#cloud-config
hostname: <%= @host.name %>
fqdn: <%= @host %>
manage_etc_hosts: true
users: {}
runcmd:
- |
<%= indent(2) { snippet('puppet_setup customized', :variables => { :full_puppet_run => true }) } %>
phone_home:
url: <%= foreman_url('built') %>
post: []
tries: 10
# This is the default puppet_setup snippet
# the only line that needs to be changed is
# the actual call to puppet.
# The parameter "--tags no_such_tag" must not be passed
# as you want puppet to do a full puppet run.
# This can be done via a parameter "full_puppet_run"
# as you can see in the example below.
<%= bin_path %>/puppet agent --config <%= etc_path %>/puppet.conf --onetime <%= @host.param_true?('run-puppet-in-installer') || @full_puppet_run ? '' : '--tags no_such_tag' %> <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
# Template for VMWare customization via open-vm-tools
identity:
LinuxPrep:
domain: <%= @host.domain %>
hostName: <%= @host.shortname %>
hwClockUTC: true
timeZone: <%= @host.params['time-zone'] || 'UTC' %>
globalIPSettings:
dnsSuffixList: [<%= @host.domain %>]
<%- @host.interfaces.each do |interface| -%>
<%- next unless interface.subnet -%>
dnsServerList: [<%= interface.subnet.dns_primary %>, <%= interface.subnet.dns_secondary %>]
<%- end -%>
nicSettingMap:
<%- @host.interfaces.each do |interface| -%>
<%- next unless interface.subnet -%>
- adapter:
dnsDomain: <%= interface.domain %>
dnsServerList: [<%= interface.subnet.dns_primary %>, <%= interface.subnet.dns_secondary %>]
gateway: [<%= interface.subnet.gateway %>]
ip: <%= interface.ip %>
subnetMask: <%= interface.subnet.mask %>
<%- end -%>
@dhajoshi
Copy link

Sorry how can i use these templates for me userdata-template works but not sure how to use other 2, please share some doc.

@shenhf
Copy link

shenhf commented Aug 20, 2018

Me too. Thanks for sharing. Would you share how to make phone_home and runcmd works?

@orelops
Copy link

orelops commented Apr 1, 2020

Hi !

How use these templates for me too userdata template works :) but how to use other 2 ?

thks

@timogoebel
Copy link
Author

These templates should be part of Foreman core starting with Foreman 1.23. These features have been incubated in a plugin. The plugin README describes the necessary steps to set this up. Note, that you don't need to have the plugin installed in Foreman 1.23 and newer.

@orelops
Copy link

orelops commented Apr 3, 2020

Hi timogoebel !

thks for your reply, i use foreman 1.24.2, and i try to use cloud-init client with centos8 template, i have configured : 1 userdata template for the networks config and 1 cloud-init template for custom scripts post-install, and when my new vm boot, network config is ko, no ip configured, and if i use only userdata template its works ! any ideas ?

@timogoebel
Copy link
Author

How do the rendered templates look like? As a side note: For support, it‘s best to use community.theforeman.org. Do you mind posting your question there? Feel free to ping me, i‘ll answer there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment