playbook复用include
ansible_prokect目录结构
nginx目录中的tasks
拆分nginx安装及配置tasks
vim config_nginx.yml
- name: push config_nginx
copy:
src: ./nginx.conf
dest: /etc/nginx/nginx.conf
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
- name:
copy:
src: ./blog.conf
dest: /etc/nginx/conf.d
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
- name: create code directory
file:
path: /code
state: directory
owner: www
group: www
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim install_nginx.yml
- name: install nginx
yum:
name: nginx
state: present
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim start_nginx.yml
- name: start nginx
service:
name: nginx
state: started
enabled: yes
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim unzip_nginx.yml
- name: unzip wordpress
unarchive:
src: ./wordpress-5.7.2-zh_CN.tar.gz
dest: /code
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
php目录中的tasks
拆分php-fpm安装及配置tasks
vim config_php.yml
- name: configure php conf
copy:
src: ./www.conf
dest: /etc/php-fpm.d
owner: root
group: root
mode: 0644
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim install_php.yml
- name: install php-fpm server
shell: 'rpm -Uvh /tmp/*.rpm'
ignore_errors: yes
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim start_php
- name: start php-fpm server
service:
name: php-fpm
state: started
enabled: yes
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
vim unzip_php.yml
- name: unzaip php
unarchive:
src: ./php.tgz
dest: /tmp
when: ansible_hostname == 'web01' or ansible_hostname == 'web02'
优化tasks
vim youhua.yml
- name: stop firewalld server
service:
name: firewalld
state: stopped
- name: disabled selinux
selinux:
state: disabled
- name: create www group
group:
name: www
gid: 666
state: present
- name: create www user
user:
name: www
uid: 666
group: '666'
shell: /sbin/nologin
create_home: no
state: present
入口文件task.yml
vim task.yml
- hosts: all
tasks:
- include_tasks: youhua/youhua.yml
- include_tasks: nginx/install_nginx.yml
- include_tasks: nginx/config_nginx.yml
- include_tasks: nginx/unzip_nginx.yml
- include_tasks: php/unzip_php.yml
- include_tasks: php/install_php.yml
- include_tasks: php/config_php.yml
- include_tasks: nginx/start_nginx.yml
- include_tasks: php/start_php.yml
|