Search code examples
ubuntuamazon-web-servicesclouddigital-oceancloud-init

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?


Solution

  • 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