我正在尝试调试“处理程序...在主处理程序列表和侦听处理程序列表中都找不到”问题。
有--list-host、--list-tags和--list-tags选项,但没有用于列出已注册处理程序的选项。我已经使用“调试”策略和 with 运行了 ansible-playbook -vvvv,但这些似乎都没有提供任何见解。我没有看到任何可能包含此信息的“神奇”变量。
有什么方法可以显示/转储这些处理程序和/或侦听器吗?
问:“有什么方法可以显示/转储这些处理程序和/或侦听器吗?”
答:不。在ansible-playbook中,没有这样的选项(类似于 --list-host、--list-tags...)来显示/转储处理程序和/或侦听器。
注意:您可以编写剧本并自行列出处理程序。例如,下面的 playbook 从变量pb_file中读取文件并写入每个 play 中的处理程序列表
shell> cat list-handlers.yml
- name: List handlers
hosts: localhost
vars:
pb_file: "{{ pb_file|default('playbook.yml') }}"
pb_dict: "{{ lookup('file', pb_file)|from_yaml }}"
pb_handlers: "{{ dict(pb_dict|json_query('[].[name,handlers[].name]')) }}"
tasks:
- debug:
msg: |
playbook: {{ pb_file }}
{% for play,handlers in pb_handlers.items() %}
play {{ '#' }}{{ loop.index }} {{ play }}
HANDLERS: {{ handlers|d([], true)|join(', ') }}
{% endfor %}
when: pb_file is exists
Run Code Online (Sandbox Code Playgroud)
给出下面的测试手册
shell> cat pb.yml
- name: Play1 test handlers
hosts: target1,target2
tasks:
- debug:
msg: Notify handler1
changed_when: true
notify: handler1
- debug:
msg: Notify handler2
changed_when: true
notify: handler2
handlers:
- name: handler1
debug:
msg: Run handler1
- name: handler2
debug:
msg: Run handler2
- name: Play2 test handlers
hosts: target1,target2
tasks:
- debug:
msg: Play2
Run Code Online (Sandbox Code Playgroud)
列出处理程序
shell> ansible-playbook list-handlers.yml -e pb_file=pb.yml
PLAY [List handlers] *****************************************************************************************
TASK [debug] *************************************************************************************************
ok: [localhost] =>
msg: |2-
playbook: pb.yml
play #1 Play1 test handlers
HANDLERS: handler1, handler2
play #2 Play2 test handlers
HANDLERS:
PLAY RECAP ***************************************************************************************************
localhost: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1386 次 |
| 最近记录: |