← Back to team overview

cloud-init team mailing list archive

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

 

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


Follow ups

References