红帽 RHCE8 认证考试:创建 Web 内容目录

题目描述

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

  1. playbookdev 主机组中的受管节点上运行
  2. 创建符合下列要求的目录 /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/ )将生成以下输出:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Development
Development
Development

详细解析

按照题目要求,首先创建并编辑如下 playbook:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
vim /home/greg/ansible/webcontent.yml
vim /home/greg/ansible/webcontent.yml
vim /home/greg/ansible/webcontent.yml

接着,开始编写 playbook.

由于题目要求我们要求我们创建 webdev 目录并且还要可以通过网络访问此目录,于是,我们首先要调用 yum 模块进行 Apache 服务器的安装;之后,还要调用 firewalld 模块设置防火墙以允许对 http 服务的访问;接着就需要调用 service 模块重启 Apache 和防火墙,并将这两个服务设置为开机自启动;最后,根据题目要求,我们需要调用 file 模块设置 webdev 目录以及其中的文件的所属组、权限和符号链接。同时,这里需要注意的一点是,由于在 RHCE8 的考试环境中,SELinux 是强制开启的,又由于我们需要访问的 web 文件其实是一个 .html 格式的静态文件,因此,这里我们将使用 file 模块下的 setype 参数,将 webdev 目录以及其中的 index.html 文件的 SELinux 上下文设置为 httpd_sys_content_t 即可。

所需编写的 playbook 全文如下(# 号后面的是注释,仅用于辅助理解,正式考试时不需要写):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
---
- name:
hosts: dev
tasks:
- name:
service:
name: firewalld
state: restarted #make firewall running.
- name:
yum:
name: httpd
state: present
- name:
firewalld:
service: http #not httpd.
state: enabled
permanent: yes
immediate: yes
- name:
service:
name: "{{ item }}"
state: restarted
loop:
- httpd
- firewalld
- name:
file:
path: /webdev
group: webdev
mode: "2775" #'2' is Set Group ID
state: directory
setype: httpd_sys_content_t
- name:
file:
src: /webdev
dest: /var/www/html/webdev
state: link
- name:
copy:
content: "Development"
dest: /webdev/index.html #If this file is not exit, the 'content' will create it.
setype: httpd_sys_content_t
--- - name: hosts: dev tasks: - name: service: name: firewalld state: restarted #make firewall running. - name: yum: name: httpd state: present - name: firewalld: service: http #not httpd. state: enabled permanent: yes immediate: yes - name: service: name: "{{ item }}" state: restarted loop: - httpd - firewalld - name: file: path: /webdev group: webdev mode: "2775" #'2' is Set Group ID state: directory setype: httpd_sys_content_t - name: file: src: /webdev dest: /var/www/html/webdev state: link - name: copy: content: "Development" dest: /webdev/index.html #If this file is not exit, the 'content' will create it. setype: httpd_sys_content_t
---
- name:
  hosts: dev
  tasks:
    - name:
      service:
        name: firewalld
        state: restarted #make firewall running.
    - name:
      yum:
        name: httpd
        state: present
    - name:
      firewalld:
        service: http  #not httpd.
        state: enabled
        permanent: yes
        immediate: yes
    - name:
      service:
        name: "{{ item }}"
        state: restarted
      loop:
        - httpd
        - firewalld
    - name:
      file:
        path: /webdev
        group: webdev
        mode: "2775" #'2' is Set Group ID
        state: directory
        setype: httpd_sys_content_t
    - name:
      file:
        src: /webdev
        dest: /var/www/html/webdev
        state: link
    - name:
      copy:
        content: "Development"
        dest: /webdev/index.html #If this file is not exit, the 'content' will create it.
        setype: httpd_sys_content_t

接着,运行 playbook:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ansible-playbook /home/greg/ansible/webcontent.yml
ansible-playbook /home/greg/ansible/webcontent.yml
ansible-playbook /home/greg/ansible/webcontent.yml

最后,使用 curl 命令访问题目指定的链接 http://172.25.250.9/webdev/, 如果能返回 Development 就没有问题。


荒原之梦网全部内容均为原创,提供了涵盖考研数学基础知识、考研数学真题、考研数学练习题和计算机科学等方面,大量精心研发的学习资源。

豫 ICP 备 17023611 号-1 | 公网安备 - 荒原之梦 豫公网安备 41142502000132 号 | SiteMap
Copyright © 2017-2024 ZhaoKaifeng.com 版权所有 All Rights Reserved.

Copyright © 2024   zhaokaifeng.com   All Rights Reserved.
豫ICP备17023611号-1
 豫公网安备41142502000132号

荒原之梦 自豪地采用WordPress