> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://close.gitbook.io/yun-wei-bi-ji/centos/ansible/playbook-debug-yong-fa.md).

# Playbook Debug用法

### debug调试模块

* msg：调试输出的消息；
* var：将某个任务执行的输出作为变量传递给debug模块

通过debug打印输出msg信息

```yaml
---
- 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信息

```yaml
- 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定义返回执行命令，返回结果信息

```bash
---
- 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
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/centos/ansible/playbook-debug-yong-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
