Ansible脚本模块如何返回脚本中每个命令的执行结果? [英] How Ansible Script module return execution result for every command in the script?
问题描述
我使用ansible脚本模块在远程主机中执行Shell脚本.我的Shell脚本 test.sh 是
I execute a shell script in remote hosts using ansible script module. My shell script test.sh is
pwd
echo "hello"
ls -l
我的剧本是
- name: Transfer and execute a script.
hosts: server
tasks:
- name: Copy and Execute the script
script: /root/test.sh
此外,我想查看脚本中每个命令的执行结果.但是我只看结果.
Besides, I want to view the execution result of every command in the script. But i only watched result.
changed: [172.18.96.134]
changed: [172.18.96.244]
changed: [172.18.96.245]
我如何观看这样的结果:
How can i watch result like this:
/root
hello
a.txt test.txt
推荐答案
您不能.在Ansible中无法在线跟踪模块.您可以从脚本中编写自己的日志.
You can't. It's not possible to trace a module on-line in Ansible. You can write your own log from the script.
处理此类要求的一种标准方法是异步操作和轮询" ,以有效处理潜在大量主机的输出.
Ansible standard way to handle such requirements is Asynchronous Actions and Polling to efficiently handle the output of the potentially large number of hosts.
可以注册并打印模块的结果.
It's possible to register and print the module's result.
- name: Copy and Execute the script
script: /root/test.sh
register: result
- debug:
var: result.stdout
这篇关于Ansible脚本模块如何返回脚本中每个命令的执行结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!