Ansible提示:将shell模块的调试模式执行日志实时写入目标节点的文件中
备忘录
目的的中文翻译有多个选项:
1. 所欲达到的目标
2. 所追求的目标
3. 着眼点
4. 需要实现的目标
如果在使用Ansible shell模块时,想要实时确认执行的位置等信息,可以通过将执行日志写入文件来进行对应的可能性。
以下是同时将Ansible日志和日志文件写入的示例。
请提供下列内容的中文本地化版本,只需一种选项:
参考
任务的例子。
- shell: |-
set -x
exec > >(tee -a "/tmp/ansible_shell.log") 2>&1
echo "hello world."
args:
executable: /bin/bash # AIX環境などではbashを導入の上で明示的にbash指定が必要
register: r
- debug:
var: r.stdout_lines
将执行结果以追加方式记录到”/tmp/ansible_shell.log”文件中:
exec > >(tee -a “/tmp/ansible_shell.log”) 2>&1
与以下方式等效:
exec &> >(tee -a “/tmp/ansible_shell.log”)
年度需求2030项目达到预期,达到了国际竞争水平,同时也满足了国内市场的需求。
TASK [shell] *******************************************************************************************************************
changed: [localhost]
TASK [debug] *******************************************************************************************************************
ok: [localhost] => {
"r.stdout_lines": [
"+ echo 'hello world.'",
"hello world."
]
}
文件输出
在目标机器上
$ cat /tmp/ansible_shell.log
+ echo 'hello world.'
hello world.
即时日志确认示例
在目标设备上
$ touch /tmp/ansible_shell.log
$ tail -0 -f /tmp/ansible_shell.log
+ echo 'hello world.'
hello world.