天天看點

3、Ansible配置檔案和Inventory檔案

如果是用RPM包方式安裝的Ansible,那麼安裝完成後會生成以下檔案:

/etc/ansible                              ###存放ansible配置檔案的目錄

/etc/ansible/hosts                   ###ansible Inventory檔案

/etc/ansible/ansible.cfg        ###ansible的配置檔案

如果是pip安裝的Ansible,那麼需要手動建立這些檔案,也可以從其他地方拷貝。

ansible.cfg檔案:

擷取最新的ansible.cfg配置檔案:

<a href="https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg" target="_blank">https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg</a>

ansible.cfg檔案内容如下:

下面這個連結中有對配置檔案中各個指令的解釋:

<a href="http://ansible-tran.readthedocs.io/en/latest/docs/intro_configuration.html" target="_blank">http://ansible-tran.readthedocs.io/en/latest/docs/intro_configuration.html</a>

Inventory檔案:

Ansible 通過讀取預設的主機清單配置/etc/ansible/hosts,可以同時連接配接到多個遠端主機上執行任務,預設路徑可以通過修改 ansible.cfg 的 hostfile 參數指定路徑 

/etc/ansible/hosts 主機清單配置格式如下 :

1

2

3

4

5

6

7

8

9

10

<code>mail.example.com</code>

<code>[webservers]</code>

<code>foo.example.com</code>

<code>bar.example.com</code>

<code>[dbservers]</code>

<code>one.example.com</code>

<code>two.example.com</code>

<code>three.example.com</code>

方括号[]中是組名,用于對系統進行分類,便于對不同系統進行個别的管理

下面的連結中有對Inventory檔案更詳細的介紹:

<a href="http://ansible-tran.readthedocs.io/en/latest/docs/intro_inventory.html" target="_blank">http://ansible-tran.readthedocs.io/en/latest/docs/intro_inventory.html</a>

本文轉自 曾哥最愛 51CTO部落格,原文連結:http://blog.51cto.com/zengestudy/1789866,如需轉載請自行聯系原作者

繼續閱讀