按照下方所述,创建一个名为 /home/student/ansible/webcontent.yml 的 playbook:
该 playbook 在 dev 主机组中的受管节点上运行
创建符合下列要求的目录 /webdev:
所有者为 devops 组
具有常规权限:owner=read+write+execute,group=read+write+execute,other=read+execute
具有特殊权限: set group ID
用符号链接将/webdev目录链接到/var/www/html/webdev
创建文件 /webdev/index.html,其中包含如下所示的单行文本:Development
在 dev 主机组中主机上浏览此目录(例如 http://node1.example.com/webdev/ )将生成以下输出:
Development
[student@ansible ansible]$ cat webcontent.yml
- hosts: dev
tasks:
- name: create group devops
group:
name: devops
state: present
- name: create directory
file:
path: /webdev
group: webdev
state: directory
mode: '2775'
setype: httpd_sys_content_t
- name: install httpd
yum:
name: httpd
- name: config firewalld
firewalld:
service: http
permanent: yes
state: enabled
immediate: yes
- name: make link
file:
src: /webdev
dest: /var/www/html/webdev
state: link
- name: make index.html
copy:
content: "Development"
dest: /webdev/index.html
setype: httpd_sys_content_t
- name: start httpd service
service:
name: httpd
state: started
enabled: yes
[student@ansible ansible]$ ansible-playbook /home/student/ansible/webcontent.yml
PLAY [dev] ************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************
ok: [node1]
TASK [create group devops] ********************************************************************************************************
ok: [node1]
TASK [create directory] ***********************************************************************************************************
ok: [node1]
TASK [install httpd] **************************************************************************************************************
ok: [node1]
TASK [config firewalld] ***********************************************************************************************************
ok: [node1]
TASK [make link] ******************************************************************************************************************
changed: [node1]
TASK [make index.html] ************************************************************************************************************
changed: [node1]
TASK [start httpd service] ********************************************************************************************************
ok: [node1]
PLAY RECAP ************************************************************************************************************************
node1 : ok=8 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
//在node1上访问
[root@node1 ~]# curl http://node1.example.com/webdev/
Development