RHCE-ansible

1)安装和配置ansible以及ansible控制节点server.example.com如下:

2)创建一个名为/home/student/ansible/inventory的静态库存文件如下所示:

2.1)node1 是dev主机组的成员

2.2)node2是test主机组的成员

2.3)node1和node2是prod主机组的成员

2.4)node1是balancers主机组的一员

2.5)prod组是webservers主机组的成员

3).创建一个名为/home/student/ansible/ansible.cfg的配置文件,如下所示:

3.1主机库存文件/home/student/ansible/inventory

3.2剧本中角色的位置被定义为/home/student/ansible/roles

4)控制主机中登录student用户,remote_user = devops,开启特权升级

在Server主机安装ansible,并写入host文件
(安装前必须确认是否有python模块)

[root@server ztx]# yum install ansible 

server
在这里插入图片描述

node1
在这里插入图片描述
node2

在这里插入图片描述
在控制添加用户student

[root@server ztx]# useradd student
[student@server ~]$ mkdir ansible
[student@server ~]$ cd ansible/
[student@server ansible]$ vim inventory

在这里插入图片描述

[student@server ansible]$ vim ansible.cfg 

在这里插入图片描述查看能否看到配置文件

[student@server ansible]$ ansible --version

在这里插入图片描述
更改信息

在这里插入图片描述
添加用户devops

[root@node1 admin]# [root@node1 admin]# passwd  devops
Changing password for user devops.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
useradd devops

[root@node2 ztx]# useradd devops
[root@node2 ztx]# passwd devops
Changing password for user devops.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

实现免密登录

[student@server ansible]$ ssh-keygen  -t rsa -f  ~/.ssh/id_rsa -P "" -q
[student@server ansible]$ ssh-copy-id  -i ~/.ssh/id_rsa.pub  devops@node1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/student/.ssh/id_rsa.pub"
/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
devops@node1's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'devops@node1'"
and check to make sure that only the key(s) you wanted were added.
[student@server ansible]$ ssh-copy-id  -i ~/.ssh/id_rsa.pub  devops@node2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/student/.ssh/id_rsa.pub"
The authenticity of host 'node2 (172.25.250.12)' can't be established.
ECDSA key fingerprint is SHA256:Kl2g1gJ/9cWTXV1FmBR/dPdcCIcd+GVoFLxMuNxGQ7Y.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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
devops@node2's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'devops@node2'"
and check to make sure that only the key(s) you wanted were added.

测试免密登录
在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值