關於ansible.cfg

什麼是ansible.cfg?

在 Ansible 中,我們可以透過配置 Ansible 的組態檔案 - ansible.cfg,來指定 Ansible 要去哪裡查找 role 的路徑。

在workspace下新增ansible.cfg,並加入以下內容

1
2
3
4
5
6
[defaults]
roles_path = /path/to/roles

若有多個路徑要設定:
[defaults]
roles_path = /path/to/public_roles:/path/to/private_roles

其它參數設定

1
2
3
4
[defaults]
private_key_file = /path/to/private_key
inventory = /path/to/inventory
roles_path = /path/to/roles

上述範例檔案配置

1
2
3
4
5
6
7
8
9
workspace
├── Vagrantfile
├── ansible.cfg
├── inventory
├── playbook.yml
└── roles
└── pip
└── tasks
└── main.yml

官方其它不同檔案配置

1
2
3
4
1.設置環境變量 (ANSIBLE_CONFIG)
2.置於當前目錄下的 ansible.cfg(這次範例中使用的方法)
3.置於根目錄下的 .ansible.cfg
4.置於 /etc/ansible/ 下的 ansible.cfg