9

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?

Brad
  • 159,648
  • 54
  • 349
  • 530
anish
  • 6,884
  • 13
  • 74
  • 140
  • Have you tried something like `[sh, -c, 'curl -sk https://example.com/packages/current/install.bash | /bin/bash -s agent:certname=XYZ.com']`? – Gonfva Oct 21 '15 at 11:19

1 Answers1

5

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

Brad
  • 159,648
  • 54
  • 349
  • 530