Quando tento reiniciar o MYSQL pelo Ansible após fazer a alteração no arquivo my.cnf na máquina virtual, recebo o erro abaixo:
TASK [Criar banco de dados MySQL] ** fatal: [172.17.177.42]: FAILED! => {"changed": false, "msg": "unable to find /home/vagrant/.my.cnf. Exception message: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")"} to retry, use: --limit
Porém quando faço o mesmo processo através da máquina usando ssh não recebo erro algum no restart. Abaixo o playbook Ansible que utilizei:
---
- hosts: database
handlers:
- name: restart mysql
service:
name: mysql
state: restarted
become: yes
tasks:
- name: "Instalar as dependências do sistema operacional"
apt:
name:
- mysql-server-5.6
- python-mysqldb
state: latest
become: yes
- name: "Criar banco de dados MySQL"
mysql_db:
name: wordpress_db
state: present
login_user: root
- name: "Criar usuário wordpress no MySQL"
mysql_user:
login_user: root
name: wordpress_user
password: 12345
priv: 'wordpress_db.*:ALL'
state: present
host: '{{ item }}'
with_items:
- 'localhost'
- '127.0.0.1'
- '172.17.177.40'
- name: "Copiar arquivos"
copy:
src: 'files/my.cnf'
dest: '/etc/mysql/my.cnf'
become: yes
notify: restart mysql
- hosts: wordpress
handlers:
- name: Reiniciar o apache2
service:
name: apache2
state: restarted
become: yes
tasks:
- name: "Instalar as dependências do sistema operacional"
apt:
name:
- php5
- apache2
- libapache2-mod-php5
- php5-gd
- libssh2-php
- php5-mcrypt
- php5-mysql
state: latest
become: yes
- name: "Baixar wordpress na máquina host"
get_url:
url: 'https://wordpress.org/latest.tar.gz'
dest: '/tmp/wordpress.tar.gz'
- name: "Descompactar arquivo wordpress"
unarchive:
src: '/tmp/wordpress.tar.gz'
dest: '/var/www/'
remote_src: yes
become: yes
- name: "Copiar arquivos"
copy:
src: '/var/www/wordpress/wp-config-sample.php'
dest: '/var/www/wordpress/wp-config.php'
remote_src: yes
become: yes
- name: "Configurar wp-config com entradas do banco de dados"
replace:
path: '/var/www/wordpress/wp-config.php'
regexp: '{{ item.regex }}'
replace: '{{ item.value }}'
backup: yes
with_items:
- { regex: 'database_name_here', value: 'wordpress_db' }
- { regex: 'username_here', value: 'wordpress_user' }
- { regex: 'password_here', value: '12345' }
- { regex: 'localhost', value: '172.17.177.42'}
become: yes
- name: "Copiar arquivos do apache2 para servir wordpress"
copy:
src: 'files/000-default.conf'
dest: '/etc/apache2/sites-available/000-default.conf'
become: yes
notify:
- Reiniciar o apache2
Alguém consegue me ajudar a resolver este problema ?