ansible debug msg 在处理程序中抛出错误

ansible debug msg throws error inside handler

Playbook 运行正常,但调试消息模块抛出未定义变量错误。

---
- hosts: labservers
 become: yes
 tasks:
- name: restart httpd
 service:
     name: httpd
     state: restarted
 notify:
     - cmds
 handlers:
- name: change file details
replace:
    path: /etc/httpd/conf/magic
    regexp: 'its is nothing'
    replace: '100 notes ashes'
register: httpd_data
- name: commands out
debug:
    msg: "{{httpd_data}}"
listen: "cmds"

code in image for clear understanding

通过使用 listen 调用处理程序中的两个任务解决。

---
- hosts: labservers
become: yes
tasks:
- name: restart httpd
service:
     name: httpd
     state: restarted
notify:
     - cmds
handlers:
- name: change file details
replace:
    path: /etc/httpd/conf/magic
    regexp: '100 notes ashes'
    replace: '100 akash'
register: httpd_data
listen: "cmds"
- name: debug details
debug:
     msg:"{{ httpd_data }}"
listen: "cmds"