← Back to team overview

cloud-init team mailing list archive

Re: cloud-init user data deployed by terraform on custom AWS AMI

 

Hi Colin,
   Some notes:
   - Cloud-init run scripts as "root" user so "sudo" is unnecessary for
your commands
   - The script stdout and stderr ends up in
/var/log/cloud-init-output.log. So expect to see any errors or script
output there.
   - When writing to files in /tmp early in boot, be aware that that tmpfs
is remounted during early boot, so your /tmp/cc is likely to disappear on
occasion.
   - To ensure your runcmd was actually executed by cloud-init, I'd expect
you see a log like the following in /var/log/cloud-init.log
"Running command ['/var/lib/cloud/instance/scripts/runcmd'] with allowed
return codes [0] (shell=False, capture=False)"

On first glance user-data looks reasonable, I'm guessing you likely have an
issue with the nvme devices not showing up yet or the driver not correctly
identifying the device
on the instance.

An official bug report and attached cloud-init logs may help us in this
regard if you are unable to find the issue on the instance.
If needed, you can file that bug at
https://bugs.launchpad.net/cloud-init/+filebug
If possible, I'd minimally want to see the attached cloud-init.tar.gz that
is captured when you run `sudo cloud-init collect-logs` on your VM.

We can then better triage what's happening in the bug instead of the
mailinglist if needed.

Much thanks,
Chad

On Thu, Feb 10, 2022 at 8:39 AM Colin Williams <
colin.williams.seattle@xxxxxxxxx> wrote:

> Here's the debugging information based on Chads' response which may
> not have been delivered to the list. Note that I have to type out the
> details due to firewall and network details. It looks like everything
> is ok based on described. I do have to run the script as root for it
> to succeed. However the first command to write the dummy file doesn't
> require root.
>
> To debug further where should I specifically look for a log that
> captures the run command script execution after Shellification?
>
> Is there a way to capture any errors or even the script run itself?
>
>
> ______________________________________________________________________________________________________________________________________________
>
> 1. Yes
>
> #cloud-config
> runcmd:
>   - echo "cloud-config" > /tmp/cc
>   - sudo mkdir /lps
>   - sudo mkfs -t xfs /dev/nvme2n1
>   - sudo chmod 777 /etc/fstab
>   - sudo echo "/dev/nvme2n1 /lps xfs defaults 0 0" > /etc/fstab
>   - sudo chmod 544 /etc/fstab
>   - sudo mount -a
>   - sudo chown -R logr:logr /lps
>   - sudo chmod -R 744 /lps
>
> output : {all : '| tee -a /var/log/cloud-init-output.log'}
>
> 2. Valid cloud-config: system userdata
> 3. status: running
>     time: Wed, 09 Feb 2022 21:46:00 +0000
>     detail:
>     DataSourceEc2
>
>    when I look at  /var/lib/cloud-init.log I see relevant lines that tell
> me
>
>     util.py start: modules-config/config-runcmd: running
> config--runcmd with frequency once-per-instance
>     util.py Shellified 9 commands
>     Writing to /var/lib/cloud/instances/....
>     main.py Ran 14 modules with 0 failures
>
>     Don't see any errors
> 4. when I manually try to inoke the script without sudo
> -bash : /var/lib/path/to/instance/run-cmd : Permission denied
>
> I checked the ownership. The file is rwx owner, and owned by root root
>
> When I execute the script at  /var/lib/path/to/instance/run-cmd using
> sudo, it runs as expected.
>
> On Wed, Feb 9, 2022 at 10:31 PM Colin Williams
> <colin.williams.seattle@xxxxxxxxx> wrote:
> >
> > I made a look at /var/lib/cloud/instance/user-data.txt and it appears
> > that the cloud config script is *deployed*.
> >
> > On Wed, Feb 9, 2022 at 10:30 PM Colin Williams
> > <colin.williams.seattle@xxxxxxxxx> wrote:
> > >
> > > Hi,
> > >
> > > I am trying to mount a instance block device (non EBS) similar to
> > >
> > > https://stackoverflow.com/a/67723667
> > >
> > > With the hostname parameter in cloud config I noticed an error ( I
> > > don't recall the exact location where I saw this)
> > >
> > > I removed the hostname parameter. In the runcmd section I added a line
> > > to write a file to /tmp/cc to try to see if the script is executed. -
> > > echo "" > /tmp/cc
> > >
> > > I am not seeing any sign of execution.
> > >
> > > I made a look at /var/lib/cloud/instance/user-data.txt and it appears
> > > that the cloud config script is executed.
> > >
> > > There appears to be a systemd cloud-init.service enabled. When I look
> > > at the logs it appears to be displaying a log generating ssh key
> > > pairs.
> > > _____________________________________________________________________
> > >
> > >
> > > In order to debug this:
> > >
> > > How do I first manually execute the user-data script using cloud-init
> > > to test functionality without testing terraform deployment?
> > >
> > > How do I get better insight into the cloud-init service or why it's
> > > not executing the script?
> > >
> > > For example, I don't see anything related to the user-data script from
> > > journalctl -u cloud-init
>

References