RHCE 9版本考试资料

RHCE 9版本考试要求

01.安装和配置 Ansible

安装和配置 Ansible

按照下⽅所述,在控制节点 control上安装和配置 Ansible:

  • 安装所需的软件包
  • 创建名为 /home/greg/ansible/inventory 的静态清单⽂件,以满⾜以下要求:
    • node1 是 dev 主机组的成员
    • node2 是 test 主机组的成员
    • node3 和 node4 是 prod 主机组的成员
    • node5 是 balancers 主机组的成员
    • prod 组是 webservers 主机组的成员
  • 创建名为 /home/greg/ansible/ansible.cfg 的配置⽂件,以满⾜以下要求:
    • 主机清单⽂件为 /home/greg/ansible/inventory
    • playbook 中使⽤的⻆⾊的位置包括 /home/greg/ansible/roles
    • ⾃定义的collection⽬录在 /home/greg/ansible/mycollection

解题方法:

[虚拟机:foundation]
# 使用greg用户远程登陆到control
[kiosk@foundation0 -]$ ssh greg@control[虚拟机:172.25.250.254|control]
# 安装ansible
[greg@control ~]$ sudo yum -y install ansible-core ansible-navigator# 创建文件夹
[greg@control ~]$ mkdir -p /home/greg/ansible/roles# 切换工作目录
[greg@control ~]$ cd /home/greg/ansible# 生成ansible.cfg配置⽂件
[greg@control ansible]$ ansible-config init --disabled > /home/greg/ansible/ansible.cfg# 创建集合存储⽬录
[greg@control ansible]$ mkdir /home/greg/ansible/mycollection# 编辑配置⽂件
[greg@control ansible]$ vim ansible.cfg
[defaults]
inventory = /home/greg/ansible/inventory
remote_user = greg
host_key_checking = False
roles_path = /home/greg/ansible/roles:/usr/share/ansible/roles
collections_path=./mycollection/:.ansible/collections:/usr/share/ansible/collections
[privilege_escalation]
become=True# 确认生效的配置文件(必做操作)
[greg@control ansible]$ ansible --version
[greg@control ansible]$ ansible-galaxy list# 创建 inventory 主机清单
[greg@control ansible]$ vim /home/greg/ansible/inventory
[dev]
node1
[test]
node2
[prod]
node3
node4
[balancers]
node5
[webservers:children]
prod# 验证: 如果可以ping通所有节点,证明配置⽂件、账户、清单都没有问题。(必做操作)
[greg@control ansible]$ ansible-inventory --graph
[greg@control ansible]$ ansible all -m ping#验证:此命令可以验证podman的登录、执行环境下载正确,查看集合。(必做操作,不做后影响后续题
目使用doc以及跑剧本)
[greg@control ansible]$ podman login utility.lab.example.com -u admin -p redhat
[greg@control ansible]$ ansible-navigator images
[greg@control ansible]$ ansible-navigator collections

02.配置您的系统以使⽤默认存储库

配置您的系统以使用默认存储库

作为系统管理员,您需要在受管节点上安装软件。

请按照正⽂所述,创建⼀个名为/home/greg/ansible/yum_repo.yml ,在各个受管节点上安装 yum 存储库

存储库1:

  • 存储库的名称为 EX294_BASE
  • 描述为 EX294 base software
  • 基础 URL 为 http://content/rhel9.0/x86_64/dvd/BaseOS
  • GPG 签名检查为 启用状态
  • GPG 密钥 URL 为 http://content/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
  • 存储库为 启用状态

存储库2:

  • 存储库的名称为 EX294_STREAM
  • 描述为 EX294 stream software
  • 基础 URL 为 http://content/rhel9.0/x86_64/dvd/AppStream
  • GPG 签名检查为 启⽤状态
  • GPG 密钥 URL 为 http://content/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
  • 存储库为 启⽤状态

解题方法:

[虚拟机:172.25.250.254|control]
# 确认各个受管节点all
[greg@control ansible]$ ansible-inventory --graph# 查模块名称
[greg@control ansible]$ ansible-doc -l | grep yum# 查模块⽤法。==/EX==,在⼿册中搜索 EXAMPLE 示例
[greg@control ansible]$ ansible-doc yum_repository# 设置vim编辑器的缩进格式
[greg@control ansible]$ echo set nu ts=2 et cuc sw=2 autoindent > ~/.vimrc# 编辑剧本
[greg@control ansible]$ vim /home/greg/ansible/yum_repo.yml
---
- name: create repositoryhosts: alltasks:- name: add BaseOS repoyum_repository:name: EX294_BASEdescription: "EX294 base software"baseurl: http://content/rhel9.0/x86_64/dvd/BaseOSgpgcheck: yesgpgkey: http://content/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-releaseenabled: yes- name: add AppStream repoyum_repository:name: EX294_STREAMdescription: "EX294 stream software"baseurl: http://content/rhel9.0/x86_64/dvd/AppStreamgpgcheck: yesgpgkey: http://content/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-releaseenabled: yes# 运行剧本 (Ansible新的剧本运行方式,必须做第一题的44-47行命令)
[greg@control ansible]$ ansible-navigator run yum_repo.yml -m stdout# 验证两个仓库(BaseOS, AppStream, 必做操作)
# 验证:验证所有节点,若软件安装完毕,证明配置成功。
[greg@control ansible]$ ansible all -a 'yum repoinfo'
[greg@control ansible]$ ansible all -a 'yum -y install ftp'
[greg@control ansible]$ ansible all -a 'rpm -q ftp'

03.安装软件包

安装软件包

创建⼀个名为 /home/greg/ansible/packages.yml 的 playbook :

  • 将 php 和 mariadb 软件包安装到 dev 、 test 和 prod 主机组中的主机上
  • 将 RPM Development Tools 软件包组安装到 dev 主机组中的主机上
  • 将 dev 主机组中主机上的 所有软件包更新为最新版本

解题方法:

[虚拟机:172.25.250.254|control][greg@control ansible]$ ansible-doc -l | grep yum
[greg@control ansible]$ ansible-doc yum
[greg@control ansible]$ vim /home/greg/ansible/packages.yml
---
- name: install1hosts: dev,test,prodtasks:- name: install packagesansible.builtin.yum:name: php,mariadbstate: present
- name: install2hosts: devtasks:- name: install groupansible.builtin.yum:name: "@RPM Development Tools"state: present- name: upgrade all packagesansible.builtin.yum:name: "*"state: latest# 验证:通过查看软件安装情况,确认题目正确。(必做操作)
[greg@control ansible]$ ansible-navigator run packages.yml -m stdout[greg@control ansible]$ ansible dev,test,prod -a 'rpm -q php mariadb'[greg@control ansible]$ ansible dev -a 'yum grouplist'
...
Installed Groups:
RPM Development Tools[greg@control ansible]$ ansible dev -a 'yum update'
...
Nothing to do.

04.使用 RHEL 系统角色

使⽤ RHEL 系统⻆⾊

安装 RHEL 系统⻆⾊软件包,并创建符合以下条件的 playbook
/home/greg/ansible/selinux.yml :

  • 在 所有受管节点 上运⾏
  • 使⽤ selinux ⻆⾊
  • 配置该⻆⾊,配置被管理节点的 selinux 为 enforcing

解题方法:

[虚拟机:172.25.250.254|control]# 安装rhel-system-roles
[greg@control ansible]$ sudo yum -y install rhel-system-roles
[greg@control ansible]$ ansible-galaxy list# 指定roles的位置
[greg@control ansible]$ vim ansible.cfg
...
# additional paths to search for roles in, `colon` separated
roles_path = /home/greg/ansible/roles:/usr/share/ansible/roles# 查看角色
[greg@control ansible]$ ansible-galaxy list# 复制现有实例文件,拿来使用
[greg@control ansible]$ cp /usr/share/doc/rhel-system-roles/selinux/exampleselinux-playbook.yml /home/greg/ansible/selinux.yml
[greg@control ansible]$ vim /home/greg/ansible/selinux.yml
删除操作 :23,30d :9,19d
---
- hosts: allvars:selinux_policy: targetedselinux_state: enforcing
# prepare prerequisites which are used in this playbooktasks:- name: execute the role and catch errorsblock:- include_role:name: rhel-system-roles.selinuxrescue:
# Fail if failed for a different reason than selinux_reboot_required.- name: handle errorsfail:msg: "role failed"when: not selinux_reboot_required- name: restart managed hostshell: sleep 2 && shutdown -r now "Ansible updates triggered"async: 1poll: 0ignore_errors: true- name: wait for managed host to come backwait_for_connection:delay: 10timeout: 300- name: reapply the roleinclude_role:name: rhel-system-roles.selinux# 使用rpm包安装的角色,还是用ansible-playbook执行
# 使用集合安装的角色,要用ansible-navigator执行
[greg@control ansible]$ ansible-playbook selinux.yml# 验证:结果应为所有节点状态为Enforcing,
# 且配置⽂件/etc/selinux/config内为SELINUX=enforcing(必做操作)
[greg@control ansible]$ ansible all -m shell -a 'grep ^SELINUX=/etc/selinux/config; getenforce'
node2 | CHANGED | rc=0 >>
SELINUX=enforcing
Enforcing
node4 | CHANGED | rc=0 >>
SELINUX=enforcing
Enforcing
node5 | CHANGED | rc=0 >>
SELINUX=enforcing
Enforcing
node3 | CHANGED | rc=0 >>
SELINUX=enforcing
Enforcing
node1 | CHANGED | rc=0 >>
SELINUX=enforcing
Enforcing

05.配置conllection

配置 conllection

  • http://classroom/materials/
    • redhat-insights-1.0.7.tar.gz
    • community-general-5.5.0.tar.gz
    • redhat-rhel_system_roles-1.19.3.tar.gz
  • 上面3个安装在 /home/greg/ansible/mycollection 目录中

解题方法:

[虚拟机:172.25.250.254|control]
[greg@control ansible]$ vim requirements.yml
---
collections:
- name: http://classroom/materials/redhat-insights-1.0.7.tar.gz
- name: http://classroom/materials/community-general-5.5.0.tar.gz
- name: http://classroom/materials/redhat-rhel_system_roles-1.19.3.tar.gz[greg@control ansible]$ ansible-galaxy collection install -r requirements.yml -p /home/greg/ansible/mycollection# 验证(必做)
[greg@control ansible]$ ansible-navigator collections
[greg@control ansible]$ ansible-navigator doc community.general.filesystem -m stdout

06.使用 Ansible Galaxy 安装角色

使⽤ Ansible Galaxy 安装角色

使⽤ Ansible Galaxy 和要求⽂件 /home/greg/ansible/roles/requirements.yml 。从以下 URL 下载角色并安装到 /home/greg/ansible/roles :

  • http://classroom/materials/haproxy.tar 此⻆⾊的名称应当为 balancer
  • http://classroom/materials/phpinfo.tar 此⻆⾊的名称应当为 phpinfo

解题方法:

[虚拟机:172.25.250.254|control][greg@control ansible]$ vim /home/greg/ansible/roles/requirements.yml
---
- src: http://classroom/materials/haproxy.tar
name: balancer
- src: http://classroom/materials/phpinfo.tar
name: phpinfo
[greg@control ansible]$ ansible-galaxy install -r /home/greg/ansible/roles/requirements.yml#验证:查看到两个⻆⾊即可。(必做操作)
[greg@control ansible]$ ansible-galaxy list
# /home/greg/ansible/roles
...
- balancer, (unknown version)
- phpinfo, (unknown version)
...

07.创建和使用角色

创建和使用角色

根据下列要求,在 /home/greg/ansible/roles 中创建名为 apache 的⻆⾊:

  • httpd 软件包已安装,设为在 系统启动时启动 并 启动
  • 防火墙已启用并正在运行,并使用允许访问 Web 服务器的规则
     
  • 模板文件件 index.html.j2 已存在,用于创建具有以下输出的文件 /var/www/html/index.html :
    Welcome to HOSTNAME on IPADDRESS
    其中,HOSTNAME 是受管节点的 完全限定域名 , IPADDRESS 则是受管节点的 IP 地址。

创建⼀个名为 /home/greg/ansible/apache.yml 的 playbook:

  • 该 play 在 webservers 主机组中的主机上运⾏并将使⽤ apache ⻆⾊

解题方法:

[虚拟机:172.25.250.254|control]
[greg@control ansible]$ ansible-galaxy role init --init-path /home/greg/ansible/roles apache[greg@control ansible]$ ansible-galaxy list[greg@control ansible]$ vim roles/apache/tasks/main.yml
---
- name: Install Apacheansible.builtin.yum:name: httpdstate: latest- name: Start httpdansible.builtin.systemd:name: httpdstate: startedenabled: yes- name: Start firewalldansible.builtin.systemd:name: firewalldstate: startedenabled: yes- name: Start apacheansible.posix.firewalld:# 注意防火墙中Apache服务名不是httpdservice: httppermanent: yesstate: enabledimmediate: yes- template:# path = roles/apache/templates/src: index.html.j2dest: /var/www/html/index.html[greg@control ansible]$ vim roles/apache/templates/index.html.j2
Welcome to {{ ansible_nodename }} on {{ ansible_default_ipv4.address }}[greg@control ansible]$ vim /home/greg/ansible/apache.yml
---
- name: webservers rolehosts: webserversroles:- apache[greg@control ansible]$ ansible-navigator run apache.yml -m stdout[greg@control ansible]$ ansible webservers --list-hosts
hosts (2):
node3
node4[虚拟机:foundation]
# 验证(必做操作)
#验证:通过访问node3、4返回网页结果(可用命令行或浏览器),判断角色是否执行正常。
[kiosk@foundation0 -]$ curl http://node3
Welcome to node3.lab.example.com on 172.25.250.11
[kiosk@foundation0 -]$ curl http://node4
Welcome to node4.lab.example.com on 172.25.250.12

08.从 Ansible Galaxy 使用角色

从 Ansible Galaxy 使用角色

根据下列要求,创建⼀个名为 /home/greg/ansible/roles.yml 的 playbook :

  • playbook 中包含一个 play, 该 play 在 balancers 主机组中的主机上运行并将使用balancer 角色。
    • 此角色配置一项服务,以在 webservers 主机组中的主机之间平衡 Web 服务器请求的负载。
    • 浏览到 balancers 主机组中的主机(例如 http://172.25.250.13 )将生成以下输出:
      Welcome to node3.lab.example.com on 172.25.250.11
    • 重新加载浏览器将从另一 Web 服务器生成输出:
      Welcome to node4.lab.example.com on 172.25.250.12
  • playbook 中包含一个 play, 该 play 在 webservers 主机组中的主机上运行并将使用 phpinfo 角色。
    • 请通过 URL /hello.php 浏览到 webservers 主机组中的主机将生成以下输出:
      Hello PHP World from FQDN
    • 其中,FQDN 是主机的完全限定名称。
      Hello PHP World from node3.lab.example.com
      另外还有 PHP 配置的各种详细信息,如安装的 PHP 版本等。
  • 同样,浏览到 http://172.25.250.12/hello.php 会生成以下输出:
    Hello PHP World from node4.lab.example.com
    另外还有 PHP 配置的各种详细信息,如安装的 PHP 版本等

解题方法:

[greg@control ansible]$ vim /home/greg/ansible/roles.yml
---
- name: Use role phpinfohosts: webserversroles:- phpinfo
- name: Use role balancerhosts: balancersroles:- balancer[greg@control ansible]$ ansible-navigator run roles.yml -m stdout

09.创建和使用逻辑卷

创建和使用逻辑卷

创建⼀个名为 /home/greg/ansible/lv.yml 的 playbook ,它将在 所有受管节点 上运行以执行下列任务:

  • 创建符合以下要求的逻辑卷:
    • 逻辑卷创建在 research 卷组中
    • 逻辑卷名称为 data
    • 逻辑卷大小为 1500 MiB
  • 使用 ext4 文件系统格式化逻辑卷
  • 如果无法创建请求的逻辑卷大小,应显示错误信息,并且应改为使用大小 800MiB。
    Could not create logical volume of that size
  • 如果卷组 research 不存在,应显示错误信息
    Volume group done not exist
  • 不要以任何方式挂载逻辑卷

解题方法:

[greg@control ansible]$ ansible-navigator doc community.general.lvol -m stdout[greg@control ansible]$ ansible-navigator doc community.general.filesystem -m stdout[greg@control ansible]$ ansible-doc debug[greg@control ansible]$ ansible-doc stat[greg@control ansible]$ vim /home/greg/ansible/lv.yml
---
- name: Create LVMhosts: alltasks:- block:- name: lv 1500Mcommunity.general.lvol:vg: researchlv: datasize: 1500- name: Create ext4community.general.filesystem:fstype: ext4dev: /dev/research/datarescue:- name: Could not create lvmansible.builtin.debug:msg: Could not create logical volume of that size- name: lv 800Mcommunity.general.lvol:vg: researchlv: datasize: 800- name: Create ext4community.general.filesystem:fstype: ext4dev: /dev/research/datawhen: ansible_lvm.vgs.research is defined- debug:msg: Volume group done not existwhen: ansible_lvm.vgs.research is not defined[greg@control ansible]$ ansible-navigator run /home/greg/ansible/lv.yml -m stdout# 观察ansible剧本执⾏过程,是否符合题意,结合blkid命令查询(必做操作)
[greg@control ansible]$ ansible all -m shell -a 'lvs'
[greg@control ansible]$ ansible all -m shell -a 'blkid /dev/research/data'

10.生成主机文件

生成主机文件

  • 将一个初始模板文件从 http://classroom/materials/hosts.j2 下载到/home/greg/ansible
  • 完成该模板,以便用它生成以下文件:针对每个清单主机包含一行内容,其格式与/etc/hosts 相同
  • 将一个剧本从 http://classroom/materials/hosts.yml 下载到/home/greg/ansible ,它将使用此模板在 dev 主机组中的主机上生成文件/etc/myhosts 。

该 playbook 运⾏后, dev 主机组中主机上的⽂件 /etc/myhosts 应针对每个受管主机包含⼀⾏内容:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.250.9 node1.lab.example.com node1
172.25.250.10 node2.lab.example.com node2
172.25.250.11 node3.lab.example.com node3
172.25.250.12 node4.lab.example.com node4
172.25.250.13 node5.lab.example.com node5

注:清单主机名称的显示顺序不重要。

解题方法:

[greg@control ansible]$ ansible dev -m debug -a 'var=groups'
[greg@control ansible]$ ansible dev -m debug -a "var=groups['all']"
[greg@control ansible]$ wget http://classroom/materials/hosts.j2
[greg@control ansible]$ vim hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% for i in groups['all'] %}
{{ hostvars[i].ansible_facts.default_ipv4.address }} {{ hostvars[i].ansible_fact
{% endfor %}
[greg@control ansible]$ vim hosts.yml
---
- name: gen host filehosts: alltasks:- name: Template a file to /etc/myhoststemplate:src: /home/greg/ansible/hosts.j2dest: /etc/myhostswhen: inventory_hostname in groups.dev[greg@control ansible]$ ansible-navigator run hosts.yml -m stdout
# 验证(必做操作)
[greg@control ansible]$ ansible dev -m shell -a 'cat /etc/myhosts'

11.修改文件内容

修改文件内容

按照下⽅所述,创建⼀个名为 /home/greg/ansible/issue.yml 的 playbook :

  • 该 playbook 将在 所有清单主机 上运行
  • 该 playbook 会将 /etc/issue 的内容替换为下方所示的一行文本:
    • 在 dev 主机组中的主机上,这行文本显示为: Development
    • 在 test 主机组中的主机上,这行文本显示为: Test
    • 在 prod 主机组中的主机上,这行文本显示为: Production

解题方法:

[greg@control ansible]$ ansible dev -m debug -a 'var=inventory_hostname'
[greg@control ansible]$ ansible dev -m debug -a 'var=groups'
[greg@control ansible]$ ansible dev -m debug -a 'var=groups.dev'
[greg@control ansible]$ ansible-doc copy
[greg@control ansible]$ ansible-doc stat
[greg@control ansible]$ vim /home/greg/ansible/issue.yml
---
- name: modify filehosts: alltasks:- name: Content 1ansible.builtin.copy:content: 'Development'dest: /etc/issuewhen: inventory_hostname in groups.dev- name: Content 2ansible.builtin.copy:content: 'Test'dest: /etc/issuewhen: inventory_hostname in groups.test- name: Content 3ansible.builtin.copy:content: 'Production'dest: /etc/issuewhen: inventory_hostname in groups.prod[greg@control ansible]$ ansible-navigator run issue.yml -m stdout# 验证(必做操作)
[greg@control ansible]$ ansible dev -a 'cat /etc/issue'
[greg@control ansible]$ ansible test -a 'cat /etc/issue'
[greg@control ansible]$ ansible prod -a 'cat /etc/issue'

12.创建 Web 内容目录

创建 Web 内容目录

按照下方所述,创建⼀个名为 /home/greg/ansible/webcontent.yml 的 playbook :

  • 该 playbook 在 dev 主机组中的受管节点上运行
  • 创建符合下列要求的目录 /webdev :
    • 所有者为 webdev 组
    • 具有常规权限:
      owner=read+write+execute,
      group=read+write+execute,
      other=read+execute
    • 具有 特殊权限 :设置组 ID
  • 用符号链接将 /var/www/html/webdev 链接到 /webdev
  • 创建文件 /webdev/index.html ,其中包含如下所示的单行文件: Development
  • 在 dev 主机组中主机上浏览此目录(例如 http://172.25.250.9/webdev/ )将生成以下输出:
    Development

解题方法:

[greg@control ansible]$ ansible-doc file
[greg@control ansible]$ ansible-doc copy
[greg@control ansible]$ ansible dev -a 'ls -ldZ /var/www/html'
-rw-r--r--. 1 root root system_u:object_r:`httpd_sys_content_t`:s0 11 Apr 14 07:11 /var/www/html[greg@control ansible]$ vim /home/greg/ansible/webcontent.yml
---
- name: Create Web Directoryhosts: devroles:- apachetasks:- name: Create directoryansible.builtin.file:path: /webdevstate: directorygroup: webdevmode: '2775'- name: Create linkansible.builtin.file:src: /webdevdest: /var/www/html/webdevstate: link- name: Copy contentansible.builtin.copy:content: 'Development'dest: /webdev/index.htmlsetype: httpd_sys_content_t[greg@control ansible]$ ansible-navigator run webcontent.yml -m stdout

13.生成硬件报告

生成硬件报告

创建⼀个名为 /home/greg/ansible/hwreport.yml 的 playbook ,它将在所有受管节点上⽣成含有以下 信息的输出⽂件 /root/hwreport.txt :

  • 清单主机名称
  • 以 MB 表示的 总内存大小
  • BIOS 版本
  • 磁盘设备 vda 的大小
  • 磁盘设备 vdb 的大小
  • 输出文件中的每一行含有一个 key=value 对

您的 playbook 应当:

  • 从 http://classroom/materials/hwreport.empty 下载文件,并将它保存为/root/hwreport.txt
  • 使用 正确的值 改为 /root/hwreport.txt
  • 如果硬件项不存在,相关的值应设为 NONE

解题方法:

[greg@control ansible]$ ansible all -m setup | grep mem
[greg@control ansible]$ ansible all -m setup | grep bios
[greg@control ansible]$ ansible all -m setup -a 'filter=*device*'
[greg@control ansible]$ curl http://materials/hwreport.empty[greg@control ansible]$ vim /home/greg/ansible/hwreport.yml
---
- name: Hardware reporthosts: alltasks:- name: Download hwreportansible.builtin.get_url:url: http://materials/hwreport.emptydest: /root/hwreport.txt- name: Report 1ansible.builtin.lineinfile:path: /root/hwreport.txtregexp: '^HOST='line: HOST={{ inventory_hostname }}- name: Report 2ansible.builtin.lineinfile:path: /root/hwreport.txtregexp: '^MEMORY='line: MEMORY={{ ansible_memtotal_mb }}- name: Report 3ansible.builtin.lineinfile:path: /root/hwreport.txtregexp: '^BIOS='line: BIOS={{ ansible_bios_version }}- name: Report 4ansible.builtin.lineinfile:path: /root/hwreport.txtregexp: '^DISK_SIZE_VDA='line: DISK_SIZE_VDA={{ ansible_devices.vda.size }}- name: Report 5ansible.builtin.lineinfile:path: /root/hwreport.txtregexp: '^DISK_SIZE_VDB='line: DISK_SIZE_VDB={{ ansible_devices.vdb.size | default('NONE', true)  }}# 验证: 收集到的报告应和各个主机的事实对⽐结果⼀致即可,请自行核对。(必做操作)
[greg@control ansible]$ ansible-navigator run hwreport.yml -m stdout
[greg@control ansible]$ ansible all -a 'cat /root/hwreport.txt'

14.创建密码库

创建密码库

按照下方所述,创建⼀个 Ansible 库来存储用户密码:

  • 库名称为 /home/greg/ansible/locker.yml
  • 库中含有两个变量,名称如下:
    • pw_developer ,值为 Imadev
    • pw_manager ,值为 Imamgr
  • 用于加密和解密该库的密码为 whenyouwishuponastar
    • 密码存储在文件 /home/greg/ansible/secret.txt 中

解题方法:

[greg@control ansible]$ vim ansible.cfg
...
vault_password_file = /home/greg/ansible/secret.txt[greg@control ansible]$ echo whenyouwishuponastar > /home/greg/ansible/secret.txt
[greg@control ansible]$ ansible-vault create /home/greg/ansible/locker.yml
---
pw_developer: Imadev
pw_manager: Imamgr[greg@control ansible]$ ansible-vault view /home/greg/ansible/locker.yml
---
pw_developer: Imadev
pw_manager: Imamgr#验证:根据推荐指令验证到文件内容被加密,且可以通过配置⽂件secret.txt⽂件⾃动解密即可。
(必做操作)
[greg@control ansible]$ cat /home/greg/ansible/locker.yml
$ANSIBLE_VAULT;1.1;AES256
3863666662376132653636383666306664633665636166366465323533396130663431393932663
1
3038366162383733643633383935663431376163646639350a39343666356636663130306465393
3
6337303063633334336262313065363336363033646164626236323964333535346665353464313
5
6162383733353561640a38333362313764656566663636306434336134653739663365323430626
3
3332613836613538343064376365393166373865663339393334346661623533363138343137313
5
666161303763323761383731343138373166653730613932343

15.创建⽤户帐户

创建用户帐户

  • 从 http://classroom/materials/user_list.yml 下载要创建的用户的列表,并将它保存到 /home/greg/ansible
  • 在本次练习中使用在其他位置创建的密码库 /home/greg/ansible/locker.yml 。创建名为 /home/greg/ansible/users.yml 的 playbook ,从而按以下所述创建用户帐户:
    • 职位描述为 developer 的用户应当:
      • 在 dev 和 test 主机组中的受管节点上创建
      • 从 pw_developer 变量分配密码
      • 密码最长有效期 30 天
      • 是补充组 devops 的成员
    • 职位描述为 manager 的用户应当:
      • 在 prod 主机组中的受管节点上创建
      • pw_manager 变量分配密码
      • 密码最长有效期 30 天
      • 是补充组 opsmgr 的成员
  • 密码采用 sha512 哈希格式。
  • 您的 playbook 应能够在本次练习中使用在其他位置创建的库密码文件/home/greg/ansible/secret.txt 正常运行。

解题方法:

[greg@control ansible]$ wget http://classroom/materials/user_list.yml
[greg@control ansible]$ cat user_list.yml[greg@control ansible]$ vim /home/greg/ansible/users.yml
---
- name: Create User1hosts: dev,testvars_files:- /home/greg/ansible/locker.yml- /home/greg/ansible/user_list.ymltasks:- name: Add group1group:name: devopsstate: present- name: Add user1user:name: "{{ item.name }}"groups: devopspassword: "{{ pw_developer | password_hash('sha512') }}"password_expire_max: "{{ item.password_expire_max }}"loop: "{{ users }}"when: item.job == 'developer'
- name: Create User2hosts: prodvars_files:- /home/greg/ansible/locker.yml- /home/greg/ansible/user_list.ymltasks:- name: Add group2group:name: opsmgrstate: present- name: Add user2user:name: "{{ item.name }}"groups: opsmgrpassword: "{{ pw_manager | password_hash('sha512') }}"password_expire_max: "{{ item.password_expire_max }}"loop: "{{ users }}"when: item.job == 'manager'[greg@control ansible]$ ansible-navigator run users.yml -m stdout# 验证: 确保 dev,test 上有bob、fred 且与题目要求⼀致(必做操作)
# 确保 pord(node3 node4) 上有 sally 且与题目要求⼀致(必做操作)
[greg@control ansible]$ ansible dev,test -m shell -a 'id bob; id sally; id fred'
[greg@control ansible]$ ansible prod -m shell -a 'id fred; id bob; id sally'[greg@control ansible]$ ssh bob@172.25.250.9
bob@172.25.250.9\'s password: `Imadev`
<Ctrl-D>
[greg@control ansible]$ ssh sally@172.25.250.12
sally@172.25.250.12\'s password: `Imamgr`
<Ctrl-D>

16.更新 Ansible 库的密钥

更新 Ansible 库的密钥

按照下⽅所述,更新现有 Ansible 库的密钥:

  • 从 http://classroom/materials/salaries.yml 下载 Ansible 库到/home/greg/ansible
  • 当前的库密码为 insecure8sure
  • 新的库密码为 bbs2you9527
  • 库使用新密码保持加密状态

解题方法:

[greg@control ansible]$ wget http://classroom/materials/salaries.yml
[greg@control ansible]$ ansible-vault rekey --ask-vault-pass salaries.yml
Vault password: `insecure8sure`
New Vault password: `bbs2you9527`
Confirm New Vault password: `bbs2you9527`
Rekey successful[greg@control ansible]$ ansible-vault view salaries.yml
Vault password: `bbs2you9527`
haha# 验证: ⽤新密码验证是否可以解密查看内容。(必做操作)
[greg@control ansible]$ ansible-vault view --ask-vault-pass salaries.yml
Vault password: `bbs2you9527`
haha

17.配置 cron 作业

配置 cron 作业

创建⼀个名为 /home/greg/ansible/cron.yml 的 playbook :

  • 该 playbook 在 test 主机组中的受管节点上运行
  • 配置 cron 作业,该作业 每隔 2 分钟 运行并执行以下命令: logger "EX200 in progress" ,以用户 natasha 身份运行

解题方法:

[greg@control ansible]$ ansible-doc -l | grep cron
[greg@control ansible]$ ansible-doc cron[greg@control ansible]$ vim /home/greg/ansible/cron.yml
---
- name: cronhosts: testtasks:- name: cron jobcron:name: "cron job1"minute: "*/2"job: 'logger "EX200 in progress"'user: natasha[greg@control ansible]$ ansible-navigator run cron.yml -m stdout# 验证:通过crontab -l -u natasha命令验证任务是否存在并正确。(必做操作)
[greg@control ansible]$ ansible test -a 'crontab -l -u natasha'
node2 | CHANGED | rc=0 >>
#Ansible: check dirs*/2 * * * * logger "EX200 in progress"

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/229158.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2.6【渲染】混合渲染

一,混合渲染简介 当应用程序使用混合渲染选项时,应用程序必须确保渲染类型之间存在同步(例如,软件渲染、Khronos API渲染和blitting)。 以下示例演示了如何将软件渲染与Khronos渲染API混合使用。您需要按照以下步骤设置渲染目标和上下文: 创建渲染目标创建渲染上下文渲…

web项目理解

1.注解开发 这是一个 Java 自定义注解的定义&#xff0c;注解的名称是 AutoFill。以下是对代码的解释&#xff1a; java Target({ElementType.METHOD}) //注解在方法上面&#xff0c;指定注解的作用范围为方法 Retention(RetentionPolicy.RUNTIME) //指定注解的生命周期为运行…

【问题思考总结】只有load和store指令能够访存有什么好处?为什么能方便实现指令流水线?【CISC与RISC的区别】【2011 408真题T18 III】

问题 今天在搜寻这个问题的时候&#xff0c;发现鲜有人关注和回答&#xff0c;因此&#xff0c;在搜寻了一些外网的回答和资料后&#xff0c;通过思考&#xff0c;总结了一些个人的愚见&#xff0c;恳请各位指正。 思考 CISC与RISC的区别之我见 首先&#xff0c;这两种架构…

0级表空间后,又有0级全库备份,再1级表空间备份,xtts还认吗?

0级表空间后&#xff0c;又有0级全库备份&#xff0c;再1级表空间备份&#xff0c;xtts还认吗&#xff1f; 不认。此时需要根据提示报错的scn号再做备份再做恢复&#xff1a; backup incremental from SCN 1041682 tablespace DATA,USERS filesperset 300 format /bak/hisdb1…

C语言指针3

1.assert(条件); 一旦条件为假则报错 2.统一关闭assert方法: 在#include<assert.h> 上一行加上#define NDEBUG 3.但是引用assert会增加程序运行的时间 4.size_t等价于unsigned int 5.关于数组首元素的地址 两个特例: sizeof,&数组名 6. int main() {int a…

13.二进制枚举练习题

文章目录 二进制枚举练习题[78. 子集](https://leetcode.cn/problems/subsets/)[77. 组合](https://leetcode.cn/problems/combinations/)[1286. 字母组合迭代器](https://leetcode.cn/problems/iterator-for-combination/)[2397. 被列覆盖的最多行数](https://leetcode.cn/pro…

【算法Hot100系列】盛最多水的容器

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

ubuntu18使用docker编译和运行的步骤

在Ubuntu 18.04上使用Docker来编译和运行应用程序主要包括以下步骤&#xff1a; 安装Docker&#xff1a; 在Ubuntu上安装Docker之前&#xff0c;首先需要更新包索引并安装一些必要的包&#xff0c;以确保能够通过HTTPS使用仓库&#xff1a; sudo apt update sudo apt install a…

【设计模式-2.4】创建型——抽象工厂模式

说明&#xff1a;本文介绍设计模式中&#xff0c;创建型设计模式的抽象工厂设计模式&#xff1b; 工厂模式的问题 在【设计模式-2.2】创建型——简单工厂和工厂模式这篇博文中&#xff0c;介绍过飞机大战游戏里&#xff0c;使用简单工厂和工厂模式来创建坦克、飞机、Boss对象…

MySQL数据库,表的增量备份与恢复

1. 从物理与逻辑的角度 数据库备份可以分为物理备份和逻辑备份。物理备份是对数据库操作系统的物理文件&#xff08;如数据 文件&#xff0c;日志文件等&#xff09;的备份。这种类型的备份适用于在出现问题时需要快速恢复的大型重要数据库。 物理备份又可以分为冷备份&#xf…

【JAVA-Day65】Java内部类深度解析

Java内部类深度解析 《Java内部类深度解析》摘要引言一、理解内部类1. 内部类的基本概念和语法1.1 什么是内部类&#xff1f;1.2 内部类的语法结构1.3 内部类的基本概念 2. 不同类型的内部类详解2.1 成员内部类2.2 静态内部类2.3 局部内部类2.4 匿名内部类 二、内部类与普通类的…

t2017030921字母矩阵

题1 字母矩阵(char) 【问题描述】 小Y才学C不久就写了一个字母矩阵的题&#xff0c;即给出一个数字N&#xff0c;画出一个最外围全是字母‘A’的中空矩形&#xff0c;当N5时形如下图: AAAAA A A A A A A AAAAA 小Q看了这个图形后&#xff0c;想了想马上给出这样一个…

【Unity自动寻路】使用Navigation系统实现物体自动寻路绕开障碍物

知识点流程图 自动导航Navigation系统 我们在游戏场景中经常会有一些障碍物、墙壁、树木等等&#xff0c;如果我想要让角色或者怪物去墙的另一边&#xff0c;我直接在墙另一边点击左键&#xff0c;我希望角色自动跑过去&#xff0c;但是他不能直接穿透墙&#xff0c;他需要“智…

04-Nacos中负载均衡规则的配置

负载均衡规则 同集群优先 默认的ZoneAvoidanceRule实现并不能根据同集群优先的规则来实现负载均衡,Nacos中提供了一个实现叫NacosRule可以优先从同集群中挑选服务实例 当服务消费者在本地集群找不到服务提供者时也会去其他集群中寻找,但此时会在服务消费者的控制台报警告 第…

六大设计原则

六大设计原则 1、单一职责原则 一个类或者模块只负责完成一个职责或者功能。 2、开放封闭原则 规定软件中的对象、类、模块和函数对扩展应该是开放的&#xff0c;对于修改应该是封闭的。用抽象定义结构&#xff0c;用具体实现扩展细节。 3、里氏替换原则 如果S是T的子类型…

STM32_串口下载程序

目录标题 前言1、理论知识2、串口下载具体操作2.1、硬件准备2.2、软件准备2.3、设置单片机的启动模式为系统存储器启动2.4、软件配置2.5、下载程序 附:生成hex文件 前言 使用调试器下载程序又快有稳定还能使用调试功能&#xff0c;当然是下载调试的首选。但是拓展下串口下载程…

BAQ压缩原理

什么是BAQ? BAQ——Block Adaptive Quantization,块自适应量化 BAQ是一种数据压缩算法。 谁提出了BAQ压缩? BAQ压缩原理是由美国NASA JPL的R. Kwok和W.T.K. Johnson在1989年提出的。第一次被用于美国NASA的“麦哲伦金星探测”任务中。 BAQ压缩的目的是什么? 上世纪后半…

Springboot Minio最新版大文件下载

上节我们说了Minio怎么大文件上传&#xff0c;我们是进行了分段上传&#xff0c;然后合并处理&#xff0c;感兴趣的可以去这篇文章&#xff0c; Springboot Minio最新版大文件上传-CSDN博客 那么今天的主题就是大文件下载&#xff0c;再大文件就需要分段下载&#xff0c;也就需…

网络爬虫第1天之数据解析库的使用

一、正则表达式 正则表达式&#xff08;Regular Expression 简称regex或regexp&#xff09;是一种强大的文本处理工具&#xff0c;它可以帮助实现快速的检索、替换或验证字符串中的特定模式。 1、match match()方法会尝试从字符串开始的位置到字符结束的位置匹配正则表达式&am…

gitee gihub上传步骤

上传 1. 到具体要上传的文件目录 2. 右击git Bash Here 初始化仓库&#xff1a;git init 3. 添加文件 添加所有文件 : git add . &#xff08;注意这里有个点&#xff09;添加具体文件&#xff1a; git add test.md 4. 添加到暂存区 git commit -m 暂存区 5. 将本地代…