安装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
在这里插入图片描述
使用rz上传
yum安装
[root@localhost ~]# yum -y install python-jinja2-2.7.2-4.el7.noarch.rpm
[root@localhost ~]# yum install -y ansible

生成公钥/私钥
在这里插入图片描述
默认生成在root家目录.ssh目录下

[root@localhost ~]# ls -ad .ssh
.ssh
私钥设置,下次登录就不需要密码了
[root@localhost ~]# ssh-copy-id -i root@192.168.1.120 //输入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
root@192.168.1.210’s password:

Number of key(s) added: 1

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

[root@localhost ~]# ssh-copy-id -i root@192.168.1.120 //输入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
root@192.168.1.195’s password:

Number of key(s) added: 1

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

配置文件

[root@localhost ~]# vim /etc/ansible/hosts
加组名ip,保存退出
在这里插入图片描述
ping自己的组名

[root@localhost ~]# ansible -m ping “fyk”
在这里插入图片描述
服务就搭建完成了
然后就可以通过以下命令对这两台机器进行操作

[root@localhost ~]# ansible test-servers -u root -a ls
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值