| 编辑apache主机playbook文件 [root@ansible playbook]# cat httpd.conf     ##需要复制过去的虚拟站点文件
<VirtualHost *:80>
    DocumentRoot "/var/www/html/"
    ServerName web.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.10.203:9000/www/html/$1
</VirtualHost>
[root@ansible playbook]#
[root@ansible playbook]# cat apache.yml 
---
- name: apache install and config
  hosts: apache
  tasks:
    - name: stop and disable firewalld
      service: 
        name: firewalld
        state: stopped
        enabled: no
    - name: disable selinux
      lineinfile:
        path: /etc/selinux/config
        regexp: "^SELINUX="
        line: "SELINUX=disabled"
        state: present
          
    - name: install httpd
      yum:
        name: httpd
        state: latest
    - name: config
      lineinfile:
        path: /etc/httpd/conf/httpd.conf
        insertafter: "    AddType application/x-gzip .gz .tgz"
        line: |
          AddType application/x-httpd-php .php
          AddType application/x-httpd-php-source .phps
    - name: config2
      lineinfile:
        path: /etc/httpd/conf/httpd.conf
        insertafter: "# LoadModule foo_module modules/mod_foo.so"
        line: |
          LoadModule proxy_module modules/mod_proxy.so
          LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    - name: config3
      lineinfile:
        path: /etc/httpd/conf/httpd.conf
        regexp: "^    DirectoryIndex"
        line: "    DirectoryIndex index.php index.html"
    - name: virtualhost
      copy:
        src: httpd.conf
        dest: /etc/httpd/conf.d/
    - name: serviec start and enable
      service:
        name: httpd
        state: started
        enabled: yes
[root@ansible playbook]#
 编辑mysql的playbook文件 [root@ansible playbook]# cat mysql.yml 
---
- name: mysql node
  hosts: mysql
  tasks:
    - name: stop and disable firewalld
      service:
        name: firewalld
        state: stopped
        enabled: no
    - name: disable selinux
      lineinfile:
        path: /etc/selinux/config
        regexp: "^SELINUX="
        line: "SELINUX=disabled"
        state: present
    - name: install mariadb-server
      yum:
        name: mariadb-server
        state: latest
    - name: install mariadb
      yum:
        name: mariadb
        state: latest
    - name: mysql start and enabled
      service:
        name: mariadb
        state: started
        enabled: yes
[root@ansible playbook]#
 编辑php的playbook文件 [root@ansible playbook]# cat index.php   ##需要复制过去的测试页文件
<?php
phpinfo();
?>
[root@ansible playbook]#
[root@ansible playbook]# cat php.yml 
---
- name: php node
  hosts: php
  tasks:
    - name: stop and disabled firewalld
      service:
        name: firewalld
        state: stopped
        enabled: no
    - name: disable selinux
      lineinfile:
        path: /etc/selinux/config
        regexp: "^SELINUX="
        line: "SELINUX=disabled"
        state: present
    - name: install php 
      yum:
        name: php*
        state: latest
    - name: config 
      lineinfile:
        path: /etc/php-fpm.d/www.conf
        regexp: "^listen = "
        line: "listen = 0.0.0.0:9000"
    - name: config2
      lineinfile:
        path: /etc/php-fpm.d/www.conf
        regexp: "listen.allowed_clients = 127.0.0.1"
        line: "listen.allowed_clients = 192.168.10.201"
    - name: create directory
      file:
        path: /www/html/
        state: directory
    - name: file index.php 
      copy:
        src: index.php
        dest: /www/html
    - name: restart and enabled service
      service:
        name: php-fpm
        state: started
        enabled: yes
[root@ansible playbook]#
 测试结果: 
 |