/srv/irclogs.ubuntu.com/2020/04/27/#cloud-init.txt

=== ananke_ is now known as ananke
=== logan_ is now known as logan-
IanTPriceI'm having an issue with the `write_files` module in cloud-init09:25
IanTPriceFor the .yaml file I'm using:09:26
IanTPrice`#cloud-configwrite_files:  - encoding: ""    path: /home/ubuntu/test.sh    owner: ubuntu:ubuntu    permissions: '0755'    append: true    content: |      #!/usr/bin/env bash      ls -lsa /home/ubuntu`09:26
IanTPriceand I'm running that using09:27
IanTPrice`multipass launch --name k5 -c 1 -d 3G -m 1G --cloud-init cloud-init/k3s-master.yaml daily:20.04`09:27
IanTPriceHowever, the code wipes out all files in the `/home/ubuntu`  directory with the exception of the `.ssh` directory09:29
IanTPriceIn addition the `owner: ubuntu:ubuntu` line has never worked09:30
IanTPriceAnyone got any ideas or links to show where I'm going wrong?09:30
SaviqIanTPrice: it's very difficult to see what your YAML actually is, can you please https://pastebin.ubuntu.com/ it ?09:31
IanTPriceI've tried many, many combinations of the `.yaml` file (BTW, multipass does a yaml validation check so I know it's not incorrect yaml09:32
SaviqIanTPrice: it doesn't have to be incorrect YAML for cloud-init to do something that you didn't expect09:32
IanTPricesaviq: will do - anyone know know how to paste multiline code in IRC?09:32
SaviqIanTPrice: your client would split it into multiple messages09:33
Saviqwould/should09:33
IanTPrice#cloud-configwrite_files:  - encoding: ""    path: /home/ubuntu/test.sh    owner: ubuntu:ubuntu    permissions: '0755'    append: true    content: |      #!/usr/bin/env bash      ls -lsa /home/ubuntu09:33
Saviqnope09:34
IanTPricehttps://pastebin.ubuntu.com/p/rWM2ntXdKR/plain/09:37
IanTPricelink including the run command: https://pastebin.ubuntu.com/p/m3mW7RcCx2/09:40
=== hjensas is now known as hjensas|afk
Odd_BlokeLongLiveCHIEF: o/ Are you still having your Pi problem?13:41
Odd_BlokeIanTPrice: I've just tested that user-data (though not in multipass) and AFAICT it's working as expected (an executable test.sh is present in /home/ubuntu, with the specified contents) with the exception of setting the owner (which I will find a bug for in a moment).  Why would you expect there to be any files in /home/ubuntu other than .ssh?13:46
=== hjensas|afk is now known as hjensas
Odd_BlokeIanTPrice: As for the owner issue, you're running into https://bugs.launchpad.net/cloud-init/+bug/1486113.  write_files runs before cloud-init creates users/groups (so that the written files can affect how users/groups are created), which causes problems in your case.  The easiest workaround is to add a runcmd which sets the permissions/ownership as you would like (as runcmd happens after both write_files13:49
ubot5Ubuntu bug 1486113 in cloud-init "write_files runs before users/groups, renders "owner" useless" [Medium,Triaged]13:49
Odd_Blokeand users/groups).13:49
IanTPriceOdd_Bloke Thanks thanks for the bug report - hadn't come across that but should be able to code around it15:37
Odd_BlokeYeah, it's an annoying one, for sure, but the workarounds are pretty simple once you know about it.15:38
Odd_BlokeHappy I could help. :)15:38
IanTPriceOdd_Bloke If I don't write the file, or if I write it to /test.sh then there are the standard files in the users home directory, namely ~/.bashrc among others15:39
IanTPriceall those files disappear if I write the file to /home/ubuntu/test.sh with the exception of the .ssh directory... ???15:40
IanTPriceJust tried it on AWS EC2 user data - it does the same thing  that helps with some elimination - it's not multipass or linux distro15:41
SaviqIanTPrice, Odd_Bloke, won't that actually be a result of the same problem?15:42
Saviqwrite_files creates /home/ubuntu, so adduser then doesn't copy the skeleton?15:42
Odd_BlokeYeah, that probably is the problem, I see what you mean now.15:54
Odd_BlokeThat's not the bug I linked though, that's specifically to do with `owner` not working as expected.15:54
Odd_BlokeAnd a search ("write_files skel") doesn't turn up any existing bugs for it.15:56
IanTPricebut you're right - it is a timing issue - I created the file in /home/newuser/test.sh and `write_files` creates the directory structure automatically15:56
IanTPriceso, as you say, `adduser` is not adding the skeleton becuase the user directory has already been created15:58
IanTPriceI could see the wood for the trees there.  many thanks for giving me the right steer - pair programming works wonders!15:59
IanTPrice*could* *couldN'T*16:00
IanTPriceThe smoking gun `The home directory `/home/newuser' already exists.  Not copying from '/etc/skel'`16:05
IanTPricePriceless: `This was first reported in 2013 in bug #1231541` =$16:11
ubot5bug 1486113 in cloud-init "duplicate for #1231541 write_files runs before users/groups, renders "owner" useless" [Medium,Triaged] https://launchpad.net/bugs/148611316:11
Odd_BlokeYeah, it's been open for a long time because changing the behaviour is backwards-incompatible.  (The trivial case to consider: a write_files to /etc/skel to ensure that all created users have the same .wibblerc in their home directories.)16:32
Odd_Blokes/behaviour/the ordering of the modules/16:33
Odd_Blokeblackboxsw: We didn't assign PRs in stand-up: I'll take the older one, and I'll assign you to the newer one.16:50
Odd_Blokeblackboxsw: I don't know why CI on your PR didn't catch this, but it looks like your schema changes introduced a pylint error: https://github.com/canonical/cloud-init/pull/33217:21
blackboxswthanks Odd_Bloke just out of mtgs. will grab it.17:22
blackboxswOdd_Bloke: typo in the comment and +1 on https://github.com/canonical/cloud-init/pull/332/files17:24
IanTPriceOdd_Bloke The suggestion of adding a `write_files_late` seems eminently suitable and should not break backwards compatability17:25

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!