Tudo estava funcionando, até criar a pasta templates e transferir o arquivo para dentro. Após isso, ao executar o teste novamente no playbook, começou a dar o seguinte erro:
`PLAY [database] ****
TASK [Gathering Facts] * fatal: [172.17.177.42]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.17.177.42 port 22: Connection timed out", "unreachable": true}
PLAY RECAP * 172.17.177.42 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0`
provisioning.yml:
`---
hosts: database handlers:
- name: restart mysql service: name: mysql state: restarted become: yes
tasks:
name: 'Instala pacotes de dependencia do sistema operacional' apt: name: ['mysql-server-5.6','python-mysqldb'] state: latest become: yes
name: 'Cria o banco do MySQL' mysql_db: name: "{{ wp_db_name }}" login_user: root state: present
name: 'Cria o usuario do MySQL' mysql_user: login_user: root name: "{{ wp_username }}" password: "{{ wp_user_password }}" priv: "{{ wp_db_name }}.*:ALL" state: present host: "{{ item }}" with_items:
- 'localhost'
- '127.0.0.1'
- "{{ wp_host_ip }}"
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: name: ['php5','apache2','libapache2-mod-php5','php5-gd','libssh2-php','php5-mcrypt','php5-mysql'] state: latest become: yes
name: 'Baixa o arquivo de instalacao do Wordpress' get_url: url: 'https://wordpress.org/wordpress-5.0.tar.gz' dest: '/tmp/wordpress.tar.gz'
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 }}" with_items:
- {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 o Wordpress' template: src: 'templates/000-default.conf.j2' dest: '/etc/apache2/sites-available/000-default.conf' become: yes notify:
- restart apache`
Hosts:
`[wordpress] 172.17.177.40 ansible_user=vagrant ansible_ssh_private_key_file="/home/leoribs/wordpress_com_ansible/.vagrant/machines/wordpress/virtualbox/private_key"
[database] 172.17.177.42 ansible_user=vagrant ansible_ssh_private_key_file="/home/leoribs/wordpress_com_ansible/.vagrant/machines/mysql/virtualbox/private_key"`
wordpress.yml:
---
wp_db_ip: '172.17.177.42'
database.yml:
---
wp_host_ip: '172.17.177.40'
all.yml:
---
wp_username: wordpress_user
wp_db_name: wordpress_db
wp_user_password: 12345
wp_installation_dir: '/var/www/wordpress'
Vagrantfile:
`Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox" do |v|
v.memory = 1024
end
config.vm.define "wordpress" do |m|
m.vm.network "private_network", ip: "172.17.177.40"
end
config.vm.define "mysql" do |m|
m.vm.network "private_network", ip: "172.17.177.42"
end
end`