开始使用Ansible
在CentOS7上
安装
sudo yum install ansible
配置文件
[defaults]
fact_caching = jsonfile
fact_caching_connection = /var/tmp/ansible/cache
fact_caching_timeout = 315360000
forks = 50
gathering = smart
inventory=<< YOUR GIT REPOSITORY >>
log_path = /var/log/ansible/ansible.log
retry_files_enabled = False
private_key_file = << YOUR PRIVATE KEY >>
[inventory]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
always = yes
context = 3
挖掘目录
mkdir -p /var/log/ansible
mkdir -p /var/tmp/ansible/cache
将该项记录在主机文件的库存中。
向目标服务器的authorized_keys文件中追加.pub文件的内容。
试试看
ansible all -m shell -a "uname -n"
如果成功的话,进行设置
ansible all -m setup
提示
-
- ansible.cfgの中でdiffをalwaysにしておくと、いちいちdry runの時に-Dのオプションをつける必要がなくてよい
- ansible.cfgの中でinventoriesをあらかじめ設定しておけば、ansibleを使ったオペレーションも本番とステージングで分ける必要がなくてよい。