Manually run cloud-init on bare metal server

599 Views Asked by At

We have a cloud-config made for virtual servers and we want to remove the virtualization layer and have the same setup on bare metal server. Is it possible to manually run that cloud-init user data script on the bare metal servers, after the server setup ? (OS install - Centos 7)

I have read about nocloud datasource for cloud-init and configuring os setup to fetch cloud-init data from an usb drive but for me it's not possible, I must find a solution to run run my user data via cloud-init manually after OS was installed

1

There are 1 best solutions below

2
On

The NoCloud datasource is still the easiest way to accomplish this. As part of install (or directly after install), you could create a filesystem (or VFS) with the files needed for NoCloud. If that's too cumbersome, you can also create a file at /etc/cloud/cloud.cfg.d/99-mydata.cfg with something like:

datasource_list: [ NoCloud ]
datasource:
  NoCloud:
    meta-data:
      instance-id: literallyanything
      local-hostname: myhostname
    user-data: |
      #cloud-config
      runcmd:
      - echo "hello from cloud-init" > /var/tmp/hello

using your cloud-config rather than what I have there. See the docs example.

To have cloud-init run, it's easiest to reboot and let cloud-init run on next boot. Cloud-init isn't really intended to be run manually, but it can be done with something like:

cloud-init init --local
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
cloud-init status --wait --long