I am having a problem with my VyOS cloud VM image where it does not run the userdata script. Firstly, I created my VyOS using the Ansible scripts from vyos-vm-images GitHub page with the following command-line arguments:
ansible-playbook qemu.yml -e disk_size=3 -e cloud_init=true -e cloud_init_ds=ConfigDrive,DigitalOcean,NoCloud,None -e keep_user=true -e enable_ssh=true -e parttable_type=mbr
After that, I uploaded it to DigitalOcean and started a new Droplet with a small userdata script to see if it works. The script is from the official documentation of VyOS on Cloud-Init with a tweak to work on DigitalOcean metadata API.
#cloud-config
write_files:
- path: /opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script
owner: root:vyattacfg
permissions: '0775'
content: |
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
hostname=$(curl -s http://169.254.169.254/metadata/v1/hostname)
configure
set system host-name $hostname
commit
exit
The script does not run at all as the VM hostname has not been changed even after a restart. However, I did notice that the userdata was written to /opt/vyatta/etc/config/cloud/instances/400456035/user-data.txt
for some reason but Cloud-Init didn’t use it. When I look into the log file of Cloud-Init at /var/log/cloud-init.log
, there is only a mention of userdata not being found. I have attached the full content of this file as attachment if you want to delve deeper.
cloud-init.log (131.1 KB)
Running grep -i -E "user" /var/log/cloud-init.log
command:
2024-02-10 11:04:28,491 - util.py[DEBUG]: Reading from /run/cloud-init/tmp/tmp7rndosxh/openstack/2012-08-10/user_data (quiet=False)
2024-02-10 11:04:28,491 - util.py[DEBUG]: Read 383 bytes from /run/cloud-init/tmp/tmp7rndosxh/openstack/2012-08-10/user_data
2024-02-10 11:04:33,494 - util.py[DEBUG]: Writing to /opt/vyatta/etc/config/cloud/instances/400456035/user-data.txt - wb: [600] 383 bytes
2024-02-10 11:04:33,519 - util.py[DEBUG]: Writing to /opt/vyatta/etc/config/cloud/instances/400456035/user-data.txt.i - wb: [600] 688 bytes
2024-02-10 11:04:33,542 - handlers.py[DEBUG]: start: init-network/consume-user-data: reading and applying user-data
2024-02-10 11:04:33,552 - handlers.py[DEBUG]: finish: init-network/consume-user-data: SUCCESS: reading and applying user-data
**2024-02-10 11:04:33,955 - main.py[DEBUG]: Skipping user-data validation. No user-data found.**
2024-02-10 11:04:35,067 - stages.py[DEBUG]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py'>) with frequency once-per-instance
2024-02-10 11:04:35,067 - handlers.py[DEBUG]: start: init-network/config-users-groups: running config-users-groups with frequency once-per-instance
2024-02-10 11:04:35,067 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/400456035/sem/config_users_groups - wb: [644] 24 bytes
2024-02-10 11:04:35,067 - helpers.py[DEBUG]: Running config-users-groups using lock (<FileLock using file '/var/lib/cloud/instances/400456035/sem/config_users_groups'>)
2024-02-10 11:04:35,139 - __init__.py[DEBUG]: created group 'lxd' for user 'ubuntu'
2024-02-10 11:04:35,139 - __init__.py[DEBUG]: Adding user ubuntu
2024-02-10 11:04:35,139 - subp.py[DEBUG]: Running hidden command to protect sensitive input/output logstring: ['useradd', 'ubuntu', '--comment', 'Ubuntu', '--groups', 'adm,audio,cdrom,dialout,dip,floppy,lxd,netdev,plugdev,sudo,video', '--shell', '/bin/bash', '-m']
2024-02-10 11:04:35,410 - util.py[DEBUG]: Writing to /etc/sudoers.d/90-cloud-init-users - wb: [440] 144 bytes
2024-02-10 11:04:35,411 - handlers.py[DEBUG]: finish: init-network/config-users-groups: SUCCESS: config-users-groups ran successfully
2024-02-10 11:04:44,290 - stages.py[DEBUG]: Running module rightscale_userdata (<module 'cloudinit.config.cc_rightscale_userdata' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_rightscale_userdata.py'>) with frequency once-per-instance
2024-02-10 11:04:44,290 - handlers.py[DEBUG]: start: modules-final/config-rightscale_userdata: running config-rightscale_userdata with frequency once-per-instance
2024-02-10 11:04:44,291 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/400456035/sem/config_rightscale_userdata - wb: [644] 25 bytes
2024-02-10 11:04:44,291 - helpers.py[DEBUG]: Running config-rightscale_userdata using lock (<FileLock using file '/var/lib/cloud/instances/400456035/sem/config_rightscale_userdata'>)
2024-02-10 11:04:44,291 - cc_rightscale_userdata.py[DEBUG]: Failed to get raw userdata in module rightscale_userdata
2024-02-10 11:04:44,291 - handlers.py[DEBUG]: finish: modules-final/config-rightscale_userdata: SUCCESS: config-rightscale_userdata ran successfully
2024-02-10 11:04:44,295 - stages.py[DEBUG]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) with frequency once-per-instance
2024-02-10 11:04:44,295 - handlers.py[DEBUG]: start: modules-final/config-scripts-user: running config-scripts-user with frequency once-per-instance
2024-02-10 11:04:44,296 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/400456035/sem/config_scripts_user - wb: [644] 25 bytes
2024-02-10 11:04:44,297 - helpers.py[DEBUG]: Running config-scripts-user using lock (<FileLock using file '/var/lib/cloud/instances/400456035/sem/config_scripts_user'>)
2024-02-10 11:04:44,297 - handlers.py[DEBUG]: finish: modules-final/config-scripts-user: SUCCESS: config-scripts-user ran successfully
The content of /var/log/cloud-init-output.log
is also pretty sparse.
Cloud-init v. 22.1-438-g41228774-1~bddeb running 'init-local' at Sat, 10 Feb 2024 11:04:28 +0000. Up 24.21 seconds.
Cloud-init v. 22.1-438-g41228774-1~bddeb running 'init' at Sat, 10 Feb 2024 11:04:33 +0000. Up 29.19 seconds.
ci-info: +++++++++++++++++++++++++++++++Net device info++++++++++++++++++++++++++++++++
ci-info: +--------+------+---------------+---------------+--------+-------------------+
ci-info: | Device | Up | Address | Mask | Scope | Hw-Address |
ci-info: +--------+------+---------------+---------------+--------+-------------------+
ci-info: | eth0 | True | 152.42.136.12 | 255.255.240.0 | global | 2e:e4:6b:74:51:32 |
ci-info: | eth1 | True | 10.110.0.2 | 255.255.240.0 | global | 3a:32:1c:68:41:fc |
ci-info: | lo | True | 127.0.0.1 | 255.0.0.0 | host | . |
ci-info: | lo | True | ::1/128 | . | host | . |
ci-info: +--------+------+---------------+---------------+--------+-------------------+
ci-info: ++++++++++++++++++++++++++++++Route IPv4 info++++++++++++++++++++++++++++++
ci-info: +-------+--------------+--------------+---------------+-----------+-------+
ci-info: | Route | Destination | Gateway | Genmask | Interface | Flags |
ci-info: +-------+--------------+--------------+---------------+-----------+-------+
ci-info: | 0 | 0.0.0.0 | 152.42.128.1 | 0.0.0.0 | eth0 | UG |
ci-info: | 1 | 10.110.0.0 | 0.0.0.0 | 255.255.240.0 | eth1 | U |
ci-info: | 2 | 152.42.128.0 | 0.0.0.0 | 255.255.240.0 | eth0 | U |
ci-info: +-------+--------------+--------------+---------------+-----------+-------+
ci-info: +++++++++++++++++++Route IPv6 info+++++++++++++++++++
ci-info: +-------+-------------+---------+-----------+-------+
ci-info: | Route | Destination | Gateway | Interface | Flags |
ci-info: +-------+-------------+---------+-----------+-------+
ci-info: | 1 | multicast | :: | eth0 | U |
ci-info: | 2 | multicast | :: | eth1 | U |
ci-info: +-------+-------------+---------+-----------+-------+
2024-02-10 11:04:35,029 - cc_resizefs.py[WARNING]: Device '/dev/overlay' did not exist. cannot resize: dev=overlay mnt_point=/ path=/
2024-02-10 11:04:38,259 - util.py[WARNING]: Failed generating key type rsa to file /etc/ssh/ssh_host_rsa_key
Generating public/private dsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_dsa_key
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub
The key fingerprint is:
SHA256:fCDQG4+/K4RIEWdZkzy7ONjQFp/jzR0bi9Ft2AX906E root@vyos-1
The key's randomart image is:
+---[DSA 1024]----+
| ..+=o. .o |
| .oo.*. o. |
| o o.O.. + ...o|
| o o Boo.= +E .o|
| . * + *S+.* .|
| o = + =.+ |
| o . |
| . . |
| ... |
+----[SHA256]-----+
Cloud-init v. 22.1-438-g41228774-1~bddeb running 'modules:config' at Sat, 10 Feb 2024 11:04:39 +0000. Up 35.80 seconds.
Cloud-init v. 22.1-438-g41228774-1~bddeb running 'modules:final' at Sat, 10 Feb 2024 11:04:43 +0000. Up 39.65 seconds.
Cloud-init v. 22.1-438-g41228774-1~bddeb finished at Sat, 10 Feb 2024 11:04:44 +0000. Datasource DataSourceConfigDrive [net,ver=2][source=/dev/vdb]. Up 40.42 seconds
I am not very familiar with Cloud-Init and this is my first time trying out on a cloud. Please let me know if I can provide any more information. Any help is appreciated!