一、源码安装

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

=================

未完待续