ansible应用进阶playbook--LNMP+WordPress
# tree.
├── group_vars
│ ├── all
│ └── all.0
├── hosts
├── LICENSE.md
├── README.md
├── roles
│ ├── common
│ │ ├── files
│ │ │ ├── epel.repo
│ │ │ ├── iptables-save
│ │ │ └── RPM-GPG-KEY-EPEL-6
│ │ ├── handlers
│ │ │ └── main.yml
│ │ └── tasks
│ │ └── main.yml
│ ├── mysql
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── my.cnf.j2
│ ├── nginx
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── default.conf
│ ├── php-fpm
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── wordpress.conf
│ └── wordpress
│ ├── tasks
│ │ └── main.yml
│ └── templates
│ └── wp-config.php
├── site.retry
└── site.yml
21 directories, 23 files
总的目录结构在上面,site.yml是总的入口
下面我们简单看下mysql部分,其他的基本都差不多
# cat site.yml
- name: Install WordPress, MySQL, Nginx, and PHP-FPM
hosts: wordpress
remote_user: root
roles:
- common
- mysql
- nginx
- php-fpm
- wordpress
# cat hosts
172.16.80.127
# cat roles/mysql/handlers/main.yml
---
- name: restart mysql
service: name=mysqld state=restarted
# cat roles/mysql/tasks/main.yml
---
- name: Install Mysql package
yum: name={{ item }} state=present
with_items:
- mysql-server
- MySQL-python
- libsemanage-python
# with_items:代表下面的列出的变量都会传到item里面
- name: Create Mysql configuration file
template: src=my.cnf.j2 dest=/etc/my.cnf
notify:
- restart mysql
- name: Start Mysql Service
service: name=mysqld state=started enabled=yes
# cat roles/mysql/templates/my.cnf.j2
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port={{ mysql_port }}
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
页:
[1]