一、源碼安裝
1、下載地址:http://releases.ansible.com/ansible/
2、管理機需要出外網,安裝的時候會下載依賴包
3、新建目錄 /etc/ansible/
4、將安裝包\ansible-2.3.0.0\examples\中 【ansible.cfg】【hosts】2個文件拷貝到/etc/ansible下
5、配置【hosts】,增加被管理的客戶機
[webservers] 10.100.28.68 10.100.28.69 [dbservers] 10.100.29.61
5、修改用於連接遠程ssh的用戶、端口、密鑰位置
# vim ansible.cfg remote_port = 31118 remote_user = root #後面創建好用戶後再來修改 private_key_file = /xjs/.ssh/id_rsa.pub
6、測試(暫時用root用戶)
#ansible all -m ping -k -k:提示輸入ssh用戶的password 10.100.28.68 | SUCCESS => { "changed": false, "ping": "pong" } 10.100.28.69 | SUCCESS => { "changed": false, "ping": "pong" } 10.100.29.61 | SUCCESS => { "changed": false, "ping": "pong" }
7、在客戶機上新建用於管理的用戶,並修改密碼
#ansible all -a 'useradd xjs' -k #ansible all -m raw -a 'echo '123456' | passwd --stdin xjs' -k
8、公鑰配置
#ssh-keygen -t rsa #ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/home/xjs/.ssh/id_rsa.pub') }}' path=/home/xjs/.ssh/authorized_keys manage_dir=no" --ask-pass -c paramiko
=================
未完待續