ansible剧本练习二

ansible剧本练习二

要求

创建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

编写剧本

[root@server ~]# su - student 
Last login: Wed Oct 26 03:06:37 CST 2022 on pts/1
[student@server ansible]$ cat webcontent.yml 
--- 

- name: web station
  hosts: dev
  tasks: 
    - name: mount dev
      mount: 
        src: /dev/cdrom
        path: /mnt
        fstype: iso9660
        state: mounted
    - name: yum_repo
      yum_repository: 
        file: server
        name: aa
        description: aa
        baseurl: file:///mnt/BaseOS
        enabled: yes
        gpgcheck: no
        
    - name: yum_repo2
      yum_repository: 
        file: server
        name: bb
        description: bb
        baseurl: file:///mnt/AppStream
        enabled: yes
        gpgcheck: no
    - name: yum httpd
      yum: 
        name: httpd
        state: latest

    - name: install semanage
      yum: 
        name: policycoreutils-python-utils
        state: latest

    - name: create group
      group: 
        name: devops
        state: present

    - name: mkdir /webdev
      file: 
        path: /webdev
        state: directory
        group: devops
        mode: 2775

    - name: /webdev/index.html
      copy: 
        content: Development
        dest: /webdev/index.html

    - name: set context
      sefcontext: 
        target: /webdev/index.html
        setype: httpd_sys_content_t
        state: present 

    - name: restorecon
      command: restorecon -Rv /webdev/index.html

    - name: creste link
      file: 
        src: /webdev
        dest: /var/www/html/webdev
        state: link

    - name: restart httpd
      service: 
        name: httpd
        state: restarted
        enabled: yes

    - name: firewalld for http
      firewalld: 
        rich_rule: rule family=ipv4 source address=192.168.87.0/24 service name=http accept
        state: enabled
        permanent: yes
        immediate: yes

执行

[student@server ansible]$ ansible-playbook webcontent.yml 

PLAY [web station] *****************************************************************************

TASK [Gathering Facts] *************************************************************************
ok: [node1]

TASK [mount dev] *******************************************************************************
changed: [node1]

TASK [yum_repo] ********************************************************************************
changed: [node1]

TASK [yum_repo2] *******************************************************************************
changed: [node1]

TASK [yum httpd] *******************************************************************************
changed: [node1]

TASK [install semanage] ************************************************************************
changed: [node1]

TASK [create group] ****************************************************************************
changed: [node1]

TASK [mkdir /webdev] ***************************************************************************
changed: [node1]

TASK [/webdev/index.html] **********************************************************************
changed: [node1]

TASK [set context] *****************************************************************************
changed: [node1]

TASK [restorecon] ******************************************************************************
changed: [node1]

TASK [creste link] *****************************************************************************
changed: [node1]

TASK [restart httpd] ***************************************************************************
changed: [node1]

TASK [firewalld for http] **********************************************************************
changed: [node1]

PLAY RECAP *************************************************************************************
node1                      : ok=14   changed=13   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

验证

[student@server ansible]$ curl http://node1.example.com/webdev/
Development
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

seven凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值