---
- hosts: database
handlers:
- name: restart mysql
service:
name: mysql
state: restarted
become: yes
tasks:
- name: 'Instala pacotes de dependencia do sistema operacional'
apt:
update_cache: yes
cache_valid_time: 3600 #1 hora
name:
- mysql-server
- python-mysqldb
state: latest
become: yes
- name: 'Cria o banco no MySQL'
mysql_db:
login_user: root
name: "{{ wp_db_name }}"
state: present
become: yes
- name: 'Cria o usuário do MySQL'
mysql_user:
login_user: root
name: "{{wp_username}}"
password: "{{wp_user_password}}"
priv: "{{wp_db_name}}.*:ALL"
state: present
host: "{{ item }}"
loop:
- 'localhost'
- '127.0.0.1'
- "{{ wp_host_ip }}"
become: yes
- name: 'Configura MySQL para aceitar conexões remotas'
copy:
src: 'files/my.cnf'
dest: '/etc/mysql/my.cnf'
become: yes
notify:
- restart mysql
- hosts: wordpress
handlers:
- name: restart apache
service:
name: apache2
state: restarted
become: yes
tasks:
- name: 'Instala pacotes de dependencia do sistema operacional'
apt:
update_cache: yes
cache_valid_time: 3600 #1 hora
name:
- php7.2
- apache2
- libapache2-mod-php7.2
- php7.2-gd
- php-ssh2
- php7.2-mysql
state: latest
become: yes
- name: 'Baixa o arquivo de instalacao do Wordpress'
get_url:
url: 'https://wordpress.org/latest.tar.gz'
dest: '/tmp/wordpress.tar.gz'
mode: 0440
- name: 'Descompacta o Wordpress'
unarchive:
src: '/tmp/wordpress.tar.gz'
dest: '/var/www/'
remote_src: yes
become: yes
- copy:
src: "{{ wp_installation_dir }}/wp-config-sample.php"
dest: "{{ wp_installation_dir }}/wp-config.php"
remote_src: yes
become: yes
- name: 'Configura o wp-config com as entradas do banco de dados'
replace:
path: "{{ wp_installation_dir }}/wp-config.php"
regexp: "{{ item.regex }}"
replace: "{{ item.value }}"
loop:
- { regex: 'database_name_here', value: "{{wp_db_name}}"}
- { regex: 'username_here', value: "{{wp_username}}"}
- { regex: 'password_here', value: "{{wp_user_password}}"}
- { regex: 'localhost', value: "{{wp_db_ip}}"}
become: yes
- name: 'Configura Apache para servir Wordpress'
template:
src: 'templates/000-default.conf.j2'
dest: '/etc/apache2/sites-available/000-default.conf'
become: yes
notify:
- restart apache
arquivo all.yml
---
wp_db_name: wordpress_db
wp_user_password: 12345
wp_username: zick
wp_installation_dir: '/var/www/wordpress'
arquivo database.yml
---
wp_host_ip: '172.17.177.40'
arquivo wordpress.yml
---
wp_db_ip: '172.17.177.42'