virsh command issue with ansible. launching command within $()

Hello All,

I have a command to run. Here is a demo of it from the ceph doco

sudo virsh secret-set-value --secret 457eb676-33da-42ec-9a8c-9293d545c337 --base64 $(cat client.cinder.key)

when I try to shell: the command below the cat command within the $() doesnt run. It outputs in a specific format I can't quite match with tr so catting it normally and removing tabs and new lines does not work for me.

virsh secret-set-value --secret 457eb676-33da-42ec-9a8c-9293d545c337 --base64 $(cat client.cinder.key)

When I try to shell: the below to set it as a variable I get

$(cat client.cinder.key)

failed: [hostname] => {“changed”: true, “cmd”: “$(cat keyring)”, “delta”: “0:00:00.008503”, “end”: “2014-09-23 07:55:37.978874”, “rc”: 127, “start”: “2014-09-23 07:55:37.970371”}
stderr: /bin/sh: [client.cinder]: command not found

[client.cinder] is the first line within the file I cat so for w/e reason it is trying to execute that it appears.

Any ideas how to stop that occuring?

thanks,
Alex

Hi Alex, are you breaking this command up over multiple lines by any chance? With the current devel branch, the shell module will interpret newlines as the start of a new command to execute, so doing this:

  • shell: |
    echo
    $(cat /path/to/foo)

will result in the contents of the file “foo” being executed similar to what you’re seeing above.

Might be good to share the playbook line where you are calling virsh?