当故障发生时,是否可以在ansible中显示调用跟踪



是否可以在ansible中追溯调用方文件?

下面是我的示例

---
# ./roles/my_role/tasks/main.yml
- include_tasks: install.yml
- include_tasks: configure.yml

我可能会在install.yml 中包含更多的文件,如check_docker.ymlinstall_docker.yml

如果失败发生在install_docker.yml中,如果像install.yml <line number>-> install_docker.yml <line num>那样调用跟踪,那么将更容易找出根本原因。

在Ansible有可能吗?

请参阅调试任务并启用调试器。例如,战术手册

shell> cat pb.yml 
- hosts: localhost
debugger: on_failed
tasks:
- include_tasks: install_docker.yml
shell> cat install_docker.yml
- name: Docker failed
command: /usr/bin/false

给出

shell> ansible-playbook pb.yml 
PLAY [localhost] ****
TASK [Gathering Facts] ****
ok: [localhost]
TASK [include_tasks] ****
included: /export/scratch/tmp/install_docker.yml for localhost
TASK [Docker failed] ****
fatal: [localhost]: FAILED! => changed=true 
cmd:
- /usr/bin/false
delta: '0:00:00.003223'
end: '2020-10-29 10:55:22.457982'
msg: non-zero return code
rc: 1
start: '2020-10-29 10:55:22.454759'
stderr: ''
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
[localhost] TASK: Docker failed (debug)> help
Documented commands (type help <topic>):
========================================
EOF  c  continue  h  help  p  pprint  q  quit  r  redo  u  update_task
[localhost] TASK: Docker failed (debug)>

增加详细信息。例如

shell> ansible-playbook test-26.yml -vvv
...
fatal: [localhost]: FAILED! => changed=true 
cmd:
- /usr/bin/false
delta: '0:00:00.002791'
end: '2020-10-29 10:57:33.372253'
invocation:
module_args:
_raw_params: /usr/bin/false
_uses_shell: false
argv: null
chdir: null
creates: null
executable: null
removes: null
stdin: null
stdin_add_newline: true
strip_empty_ends: true
warn: true
msg: non-zero return code
rc: 1
start: '2020-10-29 10:57:33.369462'
stderr: ''
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
[localhost] TASK: Docker failed (debug)> 

最新更新