2

I need to know if there is a way to print information from an ansible playbook that doesn't cause ansible to automatically quote and escape the string. For instance, I'm using ansible to build a command that should be run separately from a different machine (ironic, i know, but necessary anyhow). Currently the output looks something like...

"command" = "run_me.sh \"with this argument\"" 

What I need is something like...

"command" = run_me.sh "with this argument" 

or just...

run_me.sh "with this argument" 

if possible, but I'm guessing that's asking too much.

I'm currently using set_fact to build the command and debug to print it.

3
  • If you're wondering why I'm building commands meant to be run by hand using ansible, it's part of a bigger operation that requires checking facts on several different hosts to verify if the command needs to be run and what kind of arguments should be passed. The system running the playbook is in a dmz and doesn't have access to the necessary systems to run the command that is being built. Commented Apr 4, 2017 at 14:06
  • 1
    Languages (may) have quote level stripping support, e.g. in ZSH x='"blah de \"blah\""'; print ${(Q)x} Commented Apr 4, 2017 at 15:22
  • 1
    Just a side note: You can you delegate_to parameter to run command on hosts other than the target node. As long as the control host has access to both host groups there should be no need to run commands by hand. Commented Apr 4, 2017 at 20:14

1 Answer 1

1

You can either write your own stdout callback plugin or use some of this tricks:

--- - hosts: localhost gather_facts: no tasks: # Print as loop item - name: Print command as loop item set_fact: dummy: value # Just to make some task without output with_items: - 'Execute this: run_me.sh "with this argument"' # Print as task title # Not suitable for different commands per host, because task title is common for all hosts - name: 'Execute this: run_me.sh "with this argument"' debug: msg: Execute command from task title # Print as pause statement # Not suitable for different commands per host, because pause task skips host loop (forced run_once:yes) - name: Print command as pause statment pause: prompt: 'Execute this and press enter: run_me.sh "with this argument"' 

Output:

TASK [Print command as loop item] ********************************************** ok: [localhost] => (item=Execute this: run_me.sh "with this argument") TASK [Execute this: run_me.sh "with this argument"] **************************** ok: [localhost] => { "msg": "Execute command from task title" } TASK [Print command as pause statment] ***************************************** [Print command as pause statment] Execute this and press enter: run_me.sh "with this argument": ok: [localhost] 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.