canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
2.87k stars 856 forks source link

Traceback observed in logs while using user-data from file #5303

Open sshedi opened 4 months ago

sshedi commented 4 months ago

Bug report

While no data sources are used and user-data is provided by a file, a traceback is observed.

Steps to reproduce the problem

Following is my user-data file:

#cloud-config

preserve_hostname: true

write_files:
-   content: Hello cloudinit
    path: /var/log/cloudinit-test.log
    permissions: '0644'

And then I'm doing:

cloud-init clean -ls
cloud-init init --local
cloud-init -d modules --mode init --file user-data
cloud-init -d modules --mode config --file user-data
cloud-init -d modules --mode final --file user-data

And then in /var/log/cloud-init.log

...
2024-05-18 11:01:59,412 - util.py[DEBUG]: Failed to write boot finished file /var/lib/cloud/instance/boot-finished
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/cloudinit/config/cc_final_message.py", line 109, in handle
    util.write_file(boot_fin_fn, contents, ensure_dir_exists=False)
  File "/usr/lib/python3.11/site-packages/cloudinit/util.py", line 2308, in write_file
    with open(filename, omode) as fh:
         ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/cloud/instance/boot-finished'
2024-05-18 11:01:59,413 - cc_final_message.py[WARNING]: Used fallback datasource
...

Environment details

TheRealFalcon commented 4 months ago

@sshedi , thanks for the bug report, but I am unable to reproduce this. Would it be possible to attach the tarball resulting from cloud-init collect-logs?

Based on the traceback, it looks like cloud-init is complaing that /var/lib/cloud/instance doesn't exist when attempting to write /var/lib/cloud/instance/boot-finished. However, /var/lib/cloud/instance should get created when cloud-init init --local is run. It does when I run this locally.

sshedi commented 4 months ago

Thanks for taking a look at this. Attaching the support tarball. cloud-init.tar.gz

TheRealFalcon commented 4 months ago

Thanks. I can reproduce this when there is no datasource list defined or datasource detected.