How to use Cloud-init User-data in Foreman (PXE)

Problem:
Not able to access <foreman_url>/userdata/
Should the plugin (foreman_userdata ) be installed?

Tried to follow: RedHat Guide (Lucas)

Foreman and Proxy versions:
Foreman 2.3

Trying to boot physical live server - all I need is for TheForeman to host the userdata-directory making it reachable using NoCloud in Grub option.

Userdata plugin has been merged into Foreman in 1.23. So 1.24 and then 2.0+ already contain it.

What do you mean by “not able to access”. Only hosts with (remote) IP that is in Foreman inventory will see some result, otherwise it is HTTP 404.

Example: Create a host with IP 1.2.3.4 and then ssh to 1.2.3.4 and curl from there. Do not use NAT.

Also that blogpost is old, use:

https://docs.theforeman.org/nightly/Provisioning_Guide/index-foreman-el.html#Provisioning_Virtual_Machines_in_VMware_vSphere-Provisioning_with_cloudinit_and_userdata_templates

1 Like

Aha… Does this mean that the Foreman server must be the DHCP / knowing the IP of the host machine?
All I want is to use something like <%= foreman-url(cloud-init) %> or atleast host the foreman_url/userdata.

Reason I can not use this is because this solution expects the file:///etc/cloud/cloud.cfg.d/example_cloud-init_config.cfg being present on a VMware Template, but I have PXE live server.

Alright, so in order to use cloud-init (user-data files) Foreman assumes the IP-address is present in the host nic-entry. This is not desired/possible in my case.

Since canonical is pushing towards cloud-init (user-data & meta-data), why not create an options which not require IP-address of the client? Couldn’t it be possible to use token the same way as with preseed-files? E.g

<foreman_url>/userdata/user-data/?token=client1
<foreman_url>/userdata/user-data/?token=client2.

Creating a temporary userdata-directory for each host?..

How would you do that? Each Foreman host has a different and unique UUID token, but for this workflow you need to create a common image with the example_cloud_init_config.cfg NoCloud cloud init configuration. I don’t see a way to do this.

For preseeds Foreman generates a unique UUID token for each host, why wouldn’t this be possible for cloud-init directories? (Maybe hacky idk)
E.g. having a PXEgrub:

linux /boot/vmlinuz ds=nocloud-net\;s=http://<%= foreman_server_fqdn %>/userdata/?token=XXXX
initrd /boot/initrd

My issue is that I’m PXE metal/physical hosts using external DHCP.

I am not sure what you are doing, but cloud-init is useful when you are spawning VMs or cloud instances from images. If you are doing PXE, there is no need for cloud-init.

As I mentioned earlier; Canonical is pushing towards cloud-init (moving away from netboot image) with the new server installer (subiquity), so if I want to auto-install a Ubuntu 21.04 client I need to use the Ubuntu 21.04 live server iso w/ cloud-init integrated.

Does this clear things up_?

You mean this?

Token support for cloud-init should not be hard to implement, yeah. We can probably add it to the current sprint.

Created: Feature #33774: Add cloud-init support for tokens - Foreman

1 Like