Cloud-init install on disk

Hi,

I’m looking to automatically deploy RancherOS vms on Vsphere.
These vm are then used to deploy a RKE K8S cluster.

With govc I add the cloud-config.yml for the cloud-init:

# | cloud-init.config.data 	        | string |
govc vm.change -vm $vm -e 'guestinfo.cloud-init.config.data'=$(base64 -w0 cloud-config_master-test-1.yml)
# | cloud-init.data.encoding 	        | {“”, “base64”, “gzip+base64”} |
govc vm.change -vm $vm -e 'guestinfo.cloud-init.data.encoding'='base64'

My cloud-config cloud-config_master-test-1.yml file :

#cloud-config
hostname: master-test-1
rancher:
  cloud_init:
    datasources:
    - configdrive:/media/config-2
    - vmware
  environment:
    EXTRA_CMDLINE: /init
  network:
    dns:
      nameservers:
      - XXXX
      search:
      - XXXX
    interfaces:
      eth0:
        addresses:
        - XXXX
        gateway: XXXX
        match: eth0
      eth1:
        addresses:
        - XXXX
        gateway: XXXX
        match: eth1
  services_include:
    open-vm-tools: true
ssh_authorized_keys: 
  - ssh-rsa XXXX

And I boot on the ISO RancherOS.
The OS boot well with the configuration given in the cloud-init loaded in memory.

My question: To make the configuration persistent, I am required to do a “ros install” or is there a way to say in the cloud-init to do the installation on the disk ?

Thanks,
Aracannan

Hi Aracannan,

adding the following lines to the cloud-config file worked for me:

write_files:
permissions: “0755”
owner: root
content: |
#!/bin/bash
if [ -e /home/rancher/touched_by_local ]
then
echo “” > /etc/rc.local
else
echo “rc local checkfile” > /home/rancher/touched_by_local
wget -O /home/rancher/cloud-config.yml http://YOURSERVER.YOUR-SERVERDOMAIN/cloud-config.yml
sudo ros install -f -c /home/rancher/cloud-config.yml -d /dev/sda
fi

t.

Hi @topuli,

thanks for sharing the snippet. You are not specifying a path for he code under write files - does that work without ? Why would the code get executed ?

I am new and would be glad to understand.

Regards,
Lars

you are right, i missed a line when i copy/pasted it:

write_files:

  • path: /etc/rc.local
    permissions: “0755”
    owner: root
    content: |
    #!/bin/bash
    if [ -e /home/rancher/touched_by_local_iso ]
    then
    echo “” > /etc/rc.local
    else
    echo “rc local iso checkfile” > /home/rancher/touched_by_local_iso
    wget -O /home/rancher/cloud-config.yml http://vmdev172.adv.magwien.gv.at:88/ros/cloud-config/hru_cloud-config.yml
    sudo ros install -f -c /home/rancher/cloud-config.yml -d /dev/sda
    fi

t.