如果是用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,如需转载请自行联系原作者