clearlinux / micro-config-drive

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

runcmd doesn't seem to work properly #24

Open markdryan opened 6 years ago

markdryan commented 6 years ago

I guess I must be doing something wrong, but I'm experiencing a weird problem on clearlinux 19110. I have a cloud init file with a runcmd section that looks like this.

runcmd:
 - systemctl start sshd
 - systemctl enable sshd

ucd is not running these commands correctly. It does

/bin/sh -c "systemctl start sshd systemctl enable sshd"

which fails. I'd expect it to do

/bin/sh -c "systemctl start sshd" /bin/sh -c "systemctl enable sshd"

I don't really understand how the g_node stuff works but looking at the code

https://github.com/clearlinux/micro-config-drive/blob/master/src/ccmodules/runcmd.c#L52

It does seem like ucd concatenates all the commands in the runcmd section into one large string which it executes in one go, which is unlikely to work.

ahkok commented 6 years ago

This is a YAML language / YAML parser issue, in essence. The yaml-to-glib parser we have has issues with arrays in this way.

As you can see from the examples, wrapping the commands in [] characters will define the arrays of words as separate lists properly:

https://github.com/clearlinux/micro-config-drive/blob/master/examples/runcmd.yaml

IOW, do this instead:

runcmd:
 - [ systemctl start sshd ]
 - [ systemctl enable sshd ]

As a side note, when it comes to services, you can always do this: https://github.com/clearlinux/micro-config-drive/blob/master/examples/service.yaml

ahkok commented 6 years ago

Closing this as I think we'll keep the current behavior. Redoing the parser may be too much work.

markdryan commented 6 years ago

Thanks for the tip. I'll update my cloud-init files to use the service tag. I'm still a little worried about the bug though. From what I can tell you should be able to specify a string and not just an array of strings for each cmd. From http://cloudinit.readthedocs.io/en/latest/topics/modules.html#runcmd

Config schema:
runcmd: (array of (array of string)/(string))

Even in the example, not all the commands are wrapped in [],

https://github.com/clearlinux/micro-config-drive/blob/master/examples/runcmd.yaml#L6

Is udc processing this example correctly?

I've also found some other examples on the web where people aren't using arrays of arrays of string for runcmd, e.g.,

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

This issue might cause problems for people migrating their cloud-init files to work with udc. Is this behaviour documented somewhere?

ahkok commented 6 years ago

It processes the example correctly by sheer coincidence, since there is only one example without []s