cloud-init
cloud-init copied to clipboard
write_files as a specific user fails if folder is owned by root
Bug report
Steps to reproduce the problem
Use this cloud-init.yaml file:
#cloud-config
users:
- name: asterisk
gecos: 'Asterisk User'
groups: users
sudo: ['ALL=(ALL) NOPASSWD:ALL']
shell: /bin/bash
lock_passwd: true
write_files:
- path: /var/log/asterisk/empty.log
owner: asterisk:asterisk
permissions: '0664'
content: |
---LOG BEGINS---
The file does not get written to /var/log/asterisk/empty.log
Remove owner: asterisk:asterisk and try again, voila, it works.
Environment details
- Cloud-init version: cloud-init 24.4-0ubuntu1~24.04.2
- Operating System Distribution: Ubuntu 24.04.2
- Cloud provider, platform or installer type: Google Cloud
cloud-init logs
https://pastebin.canonical.com/p/7njH9PswGW/
@rajannpatel , if you add defer: true to your write_files definition, I think it should work:
write_files:
- path: /var/log/asterisk/empty.log
owner: asterisk:asterisk
permissions: "0664"
defer: true
content: |
---LOG BEGINS---
By default, write_files runs before users and groups get created, but defer tells it to run later in boot.