安装ansible简要
一.安装ansible
ansible安装常用两种方式,yum安装
和pip程序安装
。下面我们来详细介绍一下这两种安装方式。
1.python模块 安装
首先,我们需要安装一个python-pip
包,安装完成以后,则直接使用pip
命令来安装我们的包,具体操作过程如下:
[root@localhost ~]# yum -y install python-pip
[root@localhost ~]# pip install ansible
2.使用 yum 安装centos7
yum 安装是我们很熟悉的安装方式了。我们需要先安装一个epel-release
包,然后再安装我们的 ansible 即可。
[root@localhost ~]# yum install epel-release
[root@localhost ~]# yum install ansible
3.yum安装补充centos6
对于centos6 无法安装epel-release的安装方法
下载阿里或者清华镜像站的epel源
阿里开源镜像站: https://developer.aliyun.com/mirror/
清华开源镜像站: https://mirrors.tuna.tsinghua.edu.cn/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rm epel*
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-6.repo
[root@localhost yum.repos.d]# yum clean all
[root@master ~]# yum install ansible -y
二.免密认证
1.修改主机清单文件
[root@master ~]# vim /etc/ansible/hosts
[webserver]
192.168.100.100
192.168.100.101
2.在管理节点,生成密钥对
[root@master ~]# ssh-keygen -t rsa
3.将公钥文件发送到被管理节点
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.100.100
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.100.101
4.检查被管理节点是否在线
[root@master ~]# ansible myserver -m ping
192.168.100.100 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.100.101 | SUCCESS => {
"changed": false,
"ping": "pong"
}