---
# System prepended metadata

title: debug module & Variable - module 0
tags: [Ansible module]

---

# debug module & Variable - module 0

### debug module 介紹

[Debug module](https://medium.com/laraveldojo/%E8%AE%93%E6%82%A8%E5%AE%89%E5%BF%83%E5%9F%B7%E8%A1%8C-ansible-playbook-%E7%9A%84%E5%B0%8F%E6%8A%80%E5%B7%A7-2-856a60b19898)


## 變數使用方式
1. 全域變數
2. file import 模式
3. 區域變數

```
workspace
├── ansible.cfg
├── inventory
├── playbook.yml
├── README.md
├── roles
│   └── debug
│       └── tasks
│           └── main.yml
└── vars
    ├── demo.yml
    └── test.yml
```
- [Ubuntu 如何輸出目錄結構](https://hackmd.io/k8Zjci60TGaNSoPRbgnOaA)
## 變數優先順序
- 任務端變數優先級別高於文件變數
- 文件變數優先級高於playbook端變數
:::danger
任務端 >>> 文件變數 >>> playbook端
:::
File: playbook.yml
```yaml
  - hosts: group1 # inventory中的名稱
    
    # playbook 端參數
    vars:
      greetings: "hello from vars local"
      
    # 文件變數
    vars_files:
      - "vars/demo.yml"
      - "vars/test.yml"

    tasks:
      - name: playbook.yml running
        # 任務端
        vars:
          greetings: "hello from vars task"
        debug:
          msg: "{{ greetings }}"
          verbosity: 0

```

###### tags: `Ansible module`
