Playbook Debug用法

debug调试模块

  • msg:调试输出的消息;

  • var:将某个任务执行的输出作为变量传递给debug模块

通过debug打印输出msg信息

---
- name: install debug
  hosts: test
  vars_files:
  - /root/ansible/vars_file.yml
  - /root/ansible/vars_file01.yml
  tasks:
  - name: install {{pkg_name}}
    debug:
      msg: "{{pkg}}"

通过debug打印输出var信息

- name: install debug
  hosts: test
  vars_files:
  - /root/ansible/vars_file.yml
  - /root/ansible/vars_file01.yml
  tasks:
  - name: install {{pkg_name}}
    debug:
      msg: "{{pkg}}"
  - debug:
      var: x

通过debug打印输出register定义返回执行命令,返回结果信息

---
- name: httpd
  hosts: test

  tasks:
  - name: Command run line 
    shell: date 
    register: return_value
  - name: Show debug info 
    debug: var=return_value
    # debug: var=return_value.stdout
    # debug: var=return_value.stdout_lines

Last updated