创建Web内容目录
按照下方所述,创建一个名为 /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]$vim alone.yml
---
- name: homework
hosts: dev
tasks:
- name: yum httpd
yum:
name: httpd
state: installed
- name: httpd service
service:
name: httpd
state: restarted
enabled: yes
- name: httpd firewalld
firewalld:
service: http
permanent: yes
state: enabled
immediate: yes
- name: create group
user:
name: devops
- name: create dir
file:
path: /webdev
group: devops
state: directory
mode: 2775
setype: httpd_sys_content_t
- name: create link
file:
src: /webdev
dest: /var/www/html/webdev
state: link
- name: create file
copy:
content: "Development\n"
dest: /webdev/index.html
setype: httpd_sys_content_t
[student@ansible ~/ansible]$ansible-playbook alone.yml
******略******
PLAY RECAP
********************************************************************************
*****************************
node1 : ok=8 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
测试
[root@node1 ~]# curl http://node1/webdev/
Development
标签:httpd,group,name,练习,state,ansible,webdev
From: https://www.cnblogs.com/Archer-x/p/16830712.html