环境准备:
主机 | IP/主机名 |
---|
ansible | 192.168.235.135 | apache | 192.168.235.141 | mysql | 192.168.235.142 | php | 192.168.235.143 |
[root@wxy playbook]# cat wxy.yml
---
- name: lamp架构
hosts: apache
tasks:
- name: install httpd
yum:
name: httpd
state: present
- name: 开机自启
service:
name: httpd
state: started
enabled: yes
- name: config
lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: DirectoryIndex index.html
line: DirectoryIndex index.html index.php
- name: config2
lineinfile:
path: /etc/httpd/conf/httpd.conf
insertafter: "AddType application/x-gzip .gz .tgz"
line: "AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps"
- name: config
lineinfile:
path: /etc/httpd/conf/httpd.conf
insertafter: "# LoadModule foo_module modules/mod_foo.so"
line: "LoadModule proxy_module modules/mod_proxy.so\nLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"
- name: 在/etc/hhtpd/conf.d/httpd.conf目录下创建一个文件
shell: 'cd /etc/httpd/conf.d/'
- name:
file:
path: /etc/httpd/conf.d/httpd.conf
state: touch
- name:
shell: echo -e '<VirtualHost *:80>\n DocumentRoot /var/www/html/\n ServerName www.wzw.com\n ProxyRequests Off\n ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.235.143:9000/www/html/$1\n </VirtualHost>' >> /etc/httpd/conf.d/httpd.conf
- hosts: mysql
tasks:
- name: install mariadb
yum:
name: mariadb-*
state: present
- name: 开机自启
service:
name: mariadb.service
state: started
enabled: yes
- hosts: php
tasks:
- name:
yum:
name: php-*
state: present
- name:
service:
name: php-fpm.service
state: started
enabled: yes
- name:
lineinfile:
path: /etc/php-fpm.d/www.conf
regexp: "listen.allowed_clients = 127.0.0.1"
line: "listen.allowed_clients = 192.168.235.141"
- name:
lineinfile:
path: /etc/php-fpm.d/www.conf
regexp: "listen = /run/php-fpm/www.sock"
line: ";listen = /run/php-fpm/www.sock"
- name: 在PHP的/var/www/html目录下创建一个index.php的文件
file:
path: /var/www/html/index.php
state: touch
- name: 将index.php传到/var/www/html目录下
shell: echo -e '<?php\n phpinfo\n?>' >> /var/www/html/index.php
结果:
|