一、安装
1、安装python
# tar xvzf Python-2.7.8.tgz # cd Python-2.7.8 # ./configure --prefix=/usr/local # make --jobs=`grep processor/proc/cpuinfo | wc -l` # make install 或者直接安装好yum源 yum install python*
因为ansible是python语言写的。所以需要python的支持. 2、安装ansible 安转yum 源 rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install ansible 二、配置ansible 配置文件
(1)ansible.cfg 该文件在/etc/ansible/下 该配置文件主要定义了一些端口和文件的默认路径一般不需要修改。详细请参考: http://ju.outofmemory.cn/entry/144343 (2)主配置文件hosts 该文件的路径是/etc/ansible/hosts在ansible.cfg可定义。 [webhosts] //可以定义组
192.168.2.235 ansible_ssh_user=root ansible_ssh_pass=1234 //可以把密码定义在这,但是最好建立ssh互信最好
192.168.2.180 ansible_ssh_user=root ansible_ssh_pass=1234
192.168.2.141 ansible_ssh_user=root ansible_ssh_pass=1234
以上几个ip地址都属于webhosts 可以批量对webhosts进行管理。
三、测试
ansible是个强大的命令。
简单测试一下:ansible webhosts -m ping
出现如下:
192.168.2.141 | success >> {
"changed": false,
"ping": "pong"
}
192.168.2.235 | success >> {
"changed": false,
"ping": "pong"
}
192.168.2.180 | success >> {
"changed": false,
"ping": "pong"
}
此说明控制端和被控制端已经可以连通。
|