1. ansible安装
1.1 环境
-
centos6.5系统
-
服务端python2.6及python2.7
-
客户端只需要安装python2.5及以上和ssh
1.2 部署
(1)源码安装
安装
#git clone git://github.com/ansible/ansible.git --recursive
#cd ./ansible
#source ./hacking/env-setup
#yum -y install python-pip
#pip install paramiko PyYAML Jinja2 httplib2 six
#echo "127.0.0.1" > ~/ansible_hosts
#export ANSIBLE_HOSTS=~/ansible_hosts
#ansible all -m ping --ask-pass
升级
# git pull --rebase
# git submodule update --init --recursive
(2)yum安装
#yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
#yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#yum install ansible -y
(3)rpm安装
# git clone git://github.com/ansible/ansible.git
# cd ./ansible
# make rpm
# rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm
2. ansible配置
2.1 配置管理主机
#vim /etc/ansible/hosts
hostip
hostip
hostip
2.2 配置密钥对
#ssh-keygen -t rsa //一路回车
#ssh-agent bash
#ssh-add ~/.ssh/id_rsa
#ssh-copy-id -i ~/.ssh/id_rsa.pub root@hostip
2.3 ansible配置
#vim /etc/ansible/ansible.cfg
host_key_checking = False //禁用每次执行ansbile命令检查ssh key host
log_path = /var/log/ansible.log //日志
[accelerate] //配置ansible连接加速
accelerate_port = 10000
accelerate_multi_key = yes
2.4 测试
#ansible all -m ping
3. ssh自定义端口
有些服务器会更改SSH端口:
#vim sshd_config
#Port 22
Port 65535
更改后使用新方式进行修改配置文件
#ssh-copy-id -i ~/.ssh/id_rsa.pub -p 65535 root@172.16.1.138
配置ansible的hosts配置文件
#vim /etc/ansible/ansible.cfg
[port]
hostip
[port:vars]
ansible_ssh_user=”root”
ansible_ssh_port=65535
4. 被控制端python2.4要安装python-simplejson
#yum install python-simplejson -y