安装ansible

安装ansible

Ansible仓库默认不在yum仓库中,因此我们需要启用epel仓库
安装epel
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

安装python-jinja2-2.7.2-4.el7
网址为https://centos.pkgs.org/7/centos-x86_64/python-jinja2-2.7.2-4.el7.noarch.rpm.html
安装ansible
使用rz上传
yum安装
[[email protected] ~]# yum -y install python-jinja2-2.7.2-4.el7.noarch.rpm
[[email protected] ~]# yum install -y ansible

生成公钥/私钥
安装ansible
默认生成在root家目录.ssh目录下

[[email protected] ~]# ls -ad .ssh
.ssh
私钥设置,下次登录就不需要密码了
[[email protected] ~]# ssh-copy-id -i [email protected] //输入yes和密码
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
[email protected]’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘[email protected]’”
and check to make sure that only the key(s) you wanted were added.

[[email protected] ~]# ssh-copy-id -i [email protected] //输入yes和密码
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
[email protected]’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘[email protected]’”
and check to make sure that only the key(s) you wanted were added.

配置文件

[[email protected] ~]# vim /etc/ansible/hosts
加组名ip,保存退出
安装ansible
ping自己的组名

[[email protected] ~]# ansible -m ping “fyk”
安装ansible
服务就搭建完成了
然后就可以通过以下命令对这两台机器进行操作

[[email protected] ~]# ansible test-servers -u root -a ls
安装ansible