Hi guys,

Im having a problem when i run one playbook with my role to install and
create a database inside mysql.

The first time i run the playbook it finishes successfully.
But when i run again i get an error saying ansible canot connect to my
database.
although i can connect the database manually without a problem using my
.my.cnf file where is my root password.

This is my role Mysql:

---

- name: Instalacao de Pacotes
  yum:
    name: [ 'mariadb-server', 'python3-PyMySQL' ]
    state: latest

- name: Criação da senha de root
  command: openssl rand -base64 14 creates=/root/.my.cnf
  register: mysql_root_pass

- name: Display password
  debug:
   msg: "Password: {{ mysql_root_pass.stdout }}"
  when:
    - mysql_root_pass.changed

- name: Start Mysql
  systemd:
    name: mariadb
    enabled: true
    state: restarted

- name: Alterar a senha de root
  mysql_user:
    name: root
    host: localhost
    password: "{{ mysql_root_pass.stdout }}"
  when:
    - mysql_root_pass.changed

- name: Copiando template .my.cnf
  template: src=.my.cnf dest=/root/.my.cnf owner=root group=root mode='600'
  when:
      - mysql_root_pass.changed
  notify:
    -  Restart MariaDB
- name: Removendo o acesso Anonimo
  mysql_user: name="" host=localhost state=absent

- name: Removendo a base test
  mysql_db: name=test state=absent

- name: Criação da base de dados Wordpress
  mysql_db:
    name: 'wordpress'
    state: present
    login_user: 'root'
    login_password: "{{ mysql_root_pass.stdout }}"
    login_host: 'localhost'
    login_unix_socket: /var/lib/mysql/mysql.sock

- name: Criação do usuario Wordpress e liberaçao de acessoa  base de dados
Wordpress.
  mysql_user:
    name: 'wordpress'
    password: 'wordpress'
    priv: 'wordpress.*:ALL'
    host: '10.0.2.%'
    login_user: 'root'
    login_password: "{{ mysql_root_pass.stdout }}"
    login_host: 'localhost'


As i said, the first time i run, i got no problems:

TASK [mysql : Criação da base de dados Wordpress]
******************************
22:29:49
43
changed: [wordpress.juin.com]
44
44


But the second time, i thin i shoud receive a green "OK" because my
database is already created but i get that:

TASK [mysql : Criação da base de dados Wordpress]
******************************
22:32:12
34
fatal: [wordpress.juin.com]: FAILED! => {"changed": false, "msg": "unable
to connect to database, check login_user and login_password are correct or
/root/.my.cnf has the credentials. Exception message: (1045, \"Access
denied for user 'root'@'localhost' (using password: YES)\")"}
...

Can you help me resolve this?


-- 
Marckson Negreiros Junior

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPQqBSOThhis1g2rfaWjRVjepioY21onitm1bEpBgzVW_KAtoQ%40mail.gmail.com.

Reply via email to