我需要知道是否有一种方法可以打印出一个完整的剧本,不会自动引用和跳出string。 例如,我使用ansiblebuild立一个命令,应该从不同的机器分开运行(讽刺的是,我知道,但无论如何必要)。 目前输出看起来像…
"command" = "run_me.sh \"with this argument\""
我需要的是像…
"command" = run_me.sh "with this argument"
要不就…
run_me.sh "with this argument"
如果可能的话,但我猜这是要求太多。
我目前正在使用set_fact来build立命令和debugging打印它。
你可以写你自己的stdoutcallback插件或者使用下面的一些技巧:
--- - 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"'
输出:
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]