Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a pipe in cloud init runcmd fails

How can I use a pipe to redirect the output of a command in my runcmd section of my cloud init script? The following fails:

runcmd:
    - [curl, -sk, https://example.com/packages/current/install.bash, '|', /bin/bash, -s,  agent:certname=XYZ.com] 

It ends up creating a script that looks like this:

'curl' '-sk' 'https://example.com/packages/current/install.bash' '|' '/bin/bash' '-s' 'agent:certname=XYZ.com'

Because the pipe becomes quoted, the script fails. How can I get around this problem?

like image 804
anish Avatar asked Oct 21 '15 09:10

anish


People also ask

How do you test for Cloudinit?

You should look into /var/log/cloud-init. log and see what's there. Depending on your cloud-init user-data, the VM may even restart before it's done. However, the logs and cloud-init's analyze command should help figure out what's working as expected and what's not.

Does cloud-init need Sudo?

The entry we need to create will not need to include the username, since cloud-init is smart enough to figure out the account name from the entry information. The directive we need to use is sudo , which is aligned with our other users level directives.

How do I update Cloudinit?

Short answer: there is no supported path for running versions of cloud-init newer than 0.6. 3-0ubuntu1 on Ubuntu 12.04. However, some information on the general process may help you out. For currently supported versions of Ubuntu you can upgrade to the latest supported cloud-init with 'apt-get upgrade'.


1 Answers

Rather than using an array, use a single string.

runcmd:
    - 'curl -sk "https://example.com/packages/current/install.bash" | /bin/bash -s,  agent:certname=XYZ.com'

See also: https://www.digitalocean.com/community/questions/help-with-cloud-init-syntax-for-runcmd

like image 100
Brad Avatar answered Oct 22 '22 19:10

Brad