当前位置:网站首页>RHCE-ansible第二次作业
RHCE-ansible第二次作业
2022-07-17 00:16:00 【 ᝰꫛꫀꪝ】
1、给受管主机部署yum仓库,示例如下:
仓库1 :
Name: base
Description: baseos
Base url: https://mirrors.163.com/centos-vault/8.5.2111/BaseOS/x86_64/os/
需要验证软件包 GPG 签名
GPG key 在 /etc/pki/rpm-gpg/RPM-GPG-KEY-*
启用此软件仓库
仓库 2:
Name: app
Description: appstream
Base url: https://mirrors.163.com/centos-vault/8.5.2111/AppStream/x86_64/os/
需要验证软件包 GPG 签名
GPG key 在: /etc/pki/rpm-gpg/RPM-GPG-KEY-*
启用此软件仓库
注:检查你自己的linux系统版本,并选择相应版本仓库。
部署成功后在受管主机上安装vsftpd软件包
首先确保该工作路径下存在ansible.conf和inventory文件并且配置正确
然后vim 一个以.yml结尾的文件
这里以1-create-yum.yml为例:
[[email protected] test1]$ vim 1-create-yum.yml
然后在文件中编辑如下内容:

代码如下:
---
- name: play1
hosts: all
tasks:
- name: create base
yum_repository:
name: base
description: baseos
baseurl: https://mirrors.aliyun.com/centos-vault/8.2.2004/BaseOS/x86_64/os/
gpgcheck: yes
- name: create appstream
yum_repository:
name: app
description: appstream
baseurl: https://mirrors.aliyun.com/centos-vault/8.2.2004/AppStream/x86_64/os/
gpgcheck: yes
- name: install vsftpd
yum:
name: vsftpd
state: latest
2、给web主机组写一个playbook,该playbook有两个play,第一个play可以保证在web主机组上安装httpd和php,确保web主机组的/var/www/html/目录下面有一个文件为index.php,内容如下:
$ cat /var/www/html/index.php
<?php
phpinfo();
其中该playbook里面的第二个play用于测试该web主机组的web服务能否被成功访问index.php内容。
首先去配置文件里面去设置web组

然后去配置一个.yml文件
文件内容如下:

文件代码如下:
---
- name: play1
hosts: web
tasks:
- name: install httpd
yum:
name:
- httpd
- php
state: latest
- name: create index
copy:
content: "<?php\nphpinfo();\n"
dest: /var/www/html/index.php
- name: delete index.html
file:
path: /var/www/html/index.html
state: absent
- name: add a firewalld rule
firewalld:
service: http
permanent: true
state: enabled
immediate: true
- name: restart httpd
service:
name: httpd
state: restarted
- name: play2
hosts: master
tasks:
- name: ceshi master
uri:
url: http://master
3、在受控节点上添加一个普通用户xiaohong,配置当前控制节点的用户可以免密登录xiaohong用户,并且xiaohong可以sudo。
在控制节点上配置.yml文件
[[email protected] test1]$ vim 3-useradd.yml
文件内容如下

由于我之前配置过免密登录,所以这里就不需要产生公私钥对
如果需要
在文件内容之前加上

验证结果

文件代码如下:
---
- name: play1
hosts: node01
tasks:
- name: useradd xiaohong
user:
name: xiaohong
state: present
- name: xiaohong sudoers
lineinfile:
line: "xiaohong ALL=(ALL) NOPASSWD:ALL"
path: /etc/sudoers
- authorized_key:
state: present
user: xiaohong
key: "{
{ lookup('file', '/home/admin/.ssh/id_rsa.pub') }}"
边栏推荐
- Traversal of binary tree
- Leetcode 198:House Robber
- Test points of login function
- VLAN和TRUNK口配置
- SSH远程控制与访问
- Nmon使用方法
- 解决WIN10连接共享打印机出现0x00000709的错误
- Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,
- Performance test implementation specification Guide
- Find() (if the name is used by too many people, I will add words)
猜你喜欢

Full link voltage measurement
![[Ruiji takeout ⑩] rough learning of Linux & rough learning of redis](/img/2f/9788ddea24f090d872ccdf82ccd8d8.png)
[Ruiji takeout ⑩] rough learning of Linux & rough learning of redis

Services for NFS

Nmon使用方法

CTFHub----RCE

After unity imports the FBX model, the rotation and position of the object will change automatically at runtime

PHP pseudo protocol for command execution

Network layer transmission protocol (detailed)

C语言回调函数 & sprinf 实际应用一例

Use of sqlmap
随机推荐
For solopi app performance test
Nmon使用方法
VLAN and trunk port configuration
2022最新软件测试工具大全
正则、扩展表达式,sed文本处理器与awk工具、用脚本改IP地址
Gzip的动态压缩和静态压缩详解
Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,
2022 latest software testing tools
Leetcode buckle classic question - 42 Connect rainwater
InnoDB, MySQL structure, and the difference between the three kinds of deletion
单片机之数码管秒表的动态显示
Shell脚本case分支语句、扒匿名登录FTP的max地址
Find() (if the name is used by too many people, I will add words)
Interview: the difference between interface and abstract class - concise summary
Detailed explanation of caduceus project of metauniverse public chain (I): project concept and technical framework of caduceus metaverse protocol
Performance bottleneck positioning XMIND
How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)
Cocoon breaking and rebirth of 3D NFT: caduceus decentralized edge rendering technology
如果猎人用枪打兔子
Reprint: SQL injection common bypass