Using a pipe in cloud init runcmd fails
Asked Answered
C

1

11

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?

Constituency answered 21/10, 2015 at 9:37 Comment(1)
Have you tried something like [sh, -c, 'curl -sk https://example.com/packages/current/install.bash | /bin/bash -s agent:certname=XYZ.com']?Multitudinous
G
7

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

Gallman answered 7/11, 2015 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.