By the way something I forgot to clarify in my initial post, for the
benefit of other readers. In Foreman there are 2 ways to do image
provisioning with vmware templates and foreman, image provision with ssh,
and image provision without ssh:
http://theforeman.org/manuals/1.9/index.html#5.2.9VMwareNotes
From what I can see, the ssh approach is the better option. However
unfortunately in my company we don't use dhcp, which means that when I
tried the ssh approach, foreman did successfully instantiate a new vm out
of the vmware template, but the machine can't configure it's network
settings because of the unavailability of dhcp, so it ends up just hanging
and not doing anything else. That's why I took the 'without ssh' approach,
which involves using a user_data provisioning template.
> > Yes I did succeed. What I didnt workout yet, is puppet registration. I
> don't
> > understand why I can't combine userscript with ssh finish script. maybe
> a
> > ticket to open in redmine 
>
Thanks Claer, I will raise a ticket for this as suggested.
However as a workaround, here's what I did, first I had some prerequisites:
- I enabled autosigning of certificates on my foreman server.
- I have pre-installed puppet agent into my template, with the puppet.conf
already configured to point to my foreman server and puppetmaster. But I
have disabled the puppet agent service.
I then created an "at" job. "at" is like cron but runs a one-off job at
some date into the future, e.g. in my case i set it it to "now+5min".
Before the 5 minutes run out I quickly converted my vm into a template.
This resulted in the "at" job frozen into the template, and will actually
end up running the next time create I a vm from the template and start up
that vm. In my case I will be using my vm the following day, so well past
the 5min deadline, in this situation the 'at' command simply defaults to
running the next time the machine starts up.
In my "at" job I scheduled the task to re-enable the puppet service. When
foreman generates a new vm from this template, the vm starts up, but only
for a couple of seconds for the vmware customisation process to take place
(as well as trigger the 'at' job). The machine then reboots and this time
the puppet service started up the puppet run happens.
As a side note, I used to packer, https://packer.io/, to create my base
image vm (as well as schedule in the 'at' job). Then used a powercli script
to convert this vm into a vmware template. We then automated the whole
process into a jenkins pipeline consisting of several jobs. Some of the
latter jobs in the pipeline creates a test vm from the template, wait until
the puppet run has ended, and then and tests it with serverspec to validate
our template as well as the puppet code.
Kind regards,
Sher