中文网页参考
架构说明
ansible 采用常见的 C/S 管理方法
ansible 常见利用 ssh, scp 进行命令与文件管理
ansible 需要对管理的主机进行 ssh key 的方式进行访问
ansible 需要对管理的主机进行分组管理
常见分组方法,
对相同配置的主机可以划分到相同的分组中
一个主机可以加入多个分组
例如 初始化分组, 使用所有主机, 而 nginx 管理只适用安装 nginx 的主机
ansible 利用模板 (template) 对主机进行集中化统一管理
ansible 需python支持
本章中用到的架构
ansible server
10.199.198.218 terry-test-uq2pu.vclound.com (rhel6)
ansible client
10.199.196.233 terry-zskvt.vclound.com (rhel5)
10.199.198.161 terryzeng-gz-qa-dns-d4yzu.vclound.com (rhel6)
10.199.251.52 terryzeng-gz-qa-dns-vid7e.vclound.com (rhel6)
10.199.198.86 terry-rhel7.vclound.com (rhel7)
初始化
软件安装
rhel5 rpm download
rhel6 rpm download
rhel7 rpm download
rhel5 需额外安装软件:
yum install -y python26-jinja2 python26-paramiko python-simplejson
注意:
ansible 因推荐使用 python 2.4 以上版本
因此 rhel5 上需要额外安装软件: python-simplejson
ssh key 生成
生成 key
ssh-keygen -t rsa
免密码, 则一路回车完成
复制 key 至客户端
[root@terry-test-uq2pu .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.199.198.86
root@10.199.198.86's password: [输入 root 登录密码即可完成 ssh key 追加]
Now try logging into the machine, with "ssh 'root@10.199.198.86'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
测试
[root@terry-test-uq2pu ~]# for ip in 10.199.196.233 10.199.198.161 10.199.251.52 10.199.198.86
> do
> ssh $ip "hostname"
> done
terry-zskvt.vclound.com
terryzeng-gz-qa-dns-d4yzu.vclound.com
terryzeng-gz-qa-dns-vid7e.vclound.com
terry.rhel7.vclound.com
DNS 或 HOSTS 支持
假如没有 DNS 支持
建议把 IP, HOSTNAME 写入 /etc/hosts 文件中
具体操作(略)