是否有可能回溯调用者文件?
下面是我的例子
---
# ./roles/my_role/tasks/main.yml
- include_tasks: install.yml
- include_tasks: configure.yml
我可能会在install.yml中包含更多文件,例如check_docker.yml
和install_docker.yml
如果在install_docker.yml
中发生故障,如果呼叫跟踪类似install.yml <line number>-> install_docker.yml <line num>
,则更容易找出根本原因。
Ansible是否有可能?
答案 0 :(得分:0)
请参见Debugging tasks并启用debugger。例如,剧本
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)>