clearlinux / micro-config-drive

An alternative and small cloud-init implementation in C
Other
45 stars 17 forks source link

ec2 cloud-init: user-data script not being executed #38

Closed FrankReh closed 4 years ago

FrankReh commented 5 years ago

I'm using an AWS AMI, ami-032138b8a0ee244c9 (N. Virginia), which is a stock Clear Linux OS image built in June this year. And I'm using terraform to be able to script the creation of such EC2 instances.

At instance creation, it is not running the user data it is provisioned with. The aws console can display the user data correctly so EC2 seems to think the script provided is legitimate. Once logged into the instance via ssh, the file /var/lib/cloud/aws-user-data contains both the #cloud-config lines and the #!/bin/bash user data script lines. So the data comprising the script has made it into the image.

But there is no /var/lib/cloud/instances directory and no /var/log/cloud-init-output.log.

I'm using terraform to create the instance but this doesn't seem like a terraform issue because the user data I specified made it into instance.

It seems like the step that should pull the lines out of the before mentioned was-user-data file is not pulling those lines out.

The /var/lib/cloud/uaw-user-data file looks like this:

#cloud-config
users:
  - name: clear
    groups: wheelnopw
    ssh-authorized-keys:
      - ssh-rsa AAAA..snip..prFt EC2KeyPairName
#!/bin/bash

echo Hello World > /tmp/hello.txt
ahkok commented 5 years ago

/var/lib/cloud/instances and /var/log/cloud-init-output.log are not part of this implementation and are not created. Mixing #cloud-config and #!/bin/bash is also not supported by micro-config-drive at this moment - you should use runcmd or write_files for that instead.

I have to check if the spec supports this combined standard, and then we have to decide whether we want to support this in ucd or not, considering that we're making a minimal implemenation only.

ahkok commented 4 years ago

Upon reinspection - I can't identify a safe way to properly parse the data halfway with a YAML parser and identify where the YAML ends (since, the shebang may be part of a valid YAML statement!).

Therefore, you will have to use runcmd instead. Mixing #cloud-config with #!/bin/bash will not be supported.