1126作业(5)

1、如果当前受管主机的根分区容量大于1G,则安装httpd和mariadb-server软件包,如果httpd和mariadb服务未运行则运行该服务。

[xiaoming@centos7 chap04]$ cat  play5-1.yml
---
- hosts: node01
  tasks:
    - name: install
      yum:
        name:
            - httpd
            - mariadb-server
      when: item.mount == "/" and item.size_total > 1000000000
      loop: "{{ ansible_facts.mounts }}"
    - name: start service
      service:
         name: "{{ item }}"
         state: started
      loop:
          - httpd
          - mariadb

2、将example.conf文件复制到/etc/httpd/conf.d/目录,example.conf文件内容如下:

<virtualhost *:80>
servername 0.0.0.0
documentroot /var/www/html
</virtualhost>

<directory /var/www/html>
allowoverride none
require all granted
</directory>

如果/etc/httpd/conf.d/目录下的文件更新,则重启httpd服务。配置/var/www/html/index.html文件内容如下: zuoye

//主机
[xiaoming@centos7 chap04]$ cat example.conf
<virtualhost *:80>
servername 0.0.0.0
documentroot /var/www/html
</virtualhost>

<directory /var/www/html>
allowoverride none
require all granted
</directory>

[xiaoming@centos7 chap04]$ cat  play5-2.yml
---
- hosts: node01
  tasks:
    - copy:
        src: example.conf
        dest: /etc/httpd/conf.d/example.conf
      notify: restart httpd
    - copy:
         content: "zuoye\n"
         dest: /var/www/html/index.html
    - service:
         name: firewalld
         state: stopped

  handlers:
    - name: restart httpd
      service:
          name: httpd
          state: restarted

//受控
[root@node01 ~]# cat  /etc/httpd/conf.d/example.conf
<virtualhost *:80>
servername 0.0.0.0
documentroot /var/www/html
</virtualhost>

<directory /var/www/html>
allowoverride none
require all granted
</directory>

[root@node01 html]# pwd
/var/www/html
[root@node01 html]# cat index.html
zuoye

3、创建一个playbook,要求如下:

该playbook运行在所有受控节点

该playbook覆盖/etc/message文件的内容

在dev主机组的主机上,内容是:Development

在test主机组的主机上,内容是:Test

[xiaoming@centos7 chap04]$ cat  play5-3.yml
---
- hosts: all
  tasks:
     - copy:
         content: "development\n"
         dest: /etc/message
       when: inventory_hostname in groups.dev
     - copy:
         content: "Test\n"
         dest: /etc/message
       when: inventory_hostname in groups.test

//受控dev 
[root@node01 html]# cat /etc/message
development

//受控test
[root@node02 ~]# cat /etc/message
Test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

RongChuJie

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

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

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

打赏作者

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

抵扣说明:

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

余额充值