Estou tentando configurar um script Ansible simples para configurar uma instalação do MariaDB. No entanto, por algum motivo, posso alterar a senha do usuário root, fazer login como root com a nova senha na próxima execução, criar um banco de dados, mas se eu tentar usar mysql_user
em qualquer outro usuário, ele sempre falhará.
Manual:
---
- hosts: all
become: true
remote_user: centos
vars:
rootpwd: Password1
replipwd: Password2
dbname: tests
tasks:
- name: Installing packages
yum: name={{item}} state=latest
with_items:
- mariadb
- mariadb-server
- mariadb-devel
- name: Installing Python module
pip: name=MySQL-python
- name: Server configuration
lineinfile: dest=/etc/my.cnf line={{ item }} mode=0644 create=yes
with_items:
- bind-address=0.0.0.0
- log-bin
- server_d={{ ansible_all_ipv4_addresses[0].split('.')[3] }}
- log-basename=log{{ ansible_all_ipv4_addresses[0].split('.')[3] }}
- name: Restarting services
service: state=restarted name=mariadb enabled=yes
- name: Securing root account
mysql_user: name=root password={{ rootpwd }} priv=*.*:ALL state=present
- name: Client configuration
lineinfile: dest=/root/.my.cnf line={{ item }} mode=0600 create=yes
with_items:
- "[client]"
- user=root
- password={{ rootpwd }}
- name: Making database
mysql_db: name={{ dbname }} state=present
- name: Making replication user
mysql_user: name=replicate password={{ replipwd }} priv="*.*:REPLICATION SLAVE" state=present host="%"
Executar:
...
TASK [Restarting services] *****************************************************
task path: /home/centos/.ansible/centos-mariadb.playbook:25
changed: [172.30.1.21] => {"changed": true, "enabled": true, "name": "mariadb", "state": "started"}
changed: [172.30.1.38] => {"changed": true, "enabled": true, "name": "mariadb", "state": "started"}
TASK [Securing root account] ***************************************************
task path: /home/centos/.ansible/centos-mariadb.playbook:27
ok: [172.30.1.38] => {"changed": false, "user": "root"}
ok: [172.30.1.21] => {"changed": false, "user": "root"}
TASK [Client configuration] ****************************************************
task path: /home/centos/.ansible/centos-mariadb.playbook:30
ok: [172.30.1.21] => (item=[client]) => {"backup": "", "changed": false, "item": "[client]", "msg": ""}
ok: [172.30.1.38] => (item=[client]) => {"backup": "", "changed": false, "item": "[client]", "msg": ""}
ok: [172.30.1.21] => (item=user=root) => {"backup": "", "changed": false, "item": "user=root", "msg": ""}
ok: [172.30.1.38] => (item=user=root) => {"backup": "", "changed": false, "item": "user=root", "msg": ""}
ok: [172.30.1.21] => (item=password=Password1) => {"backup": "", "changed": false, "item": "password=Password1", "msg": ""}
ok: [172.30.1.38] => (item=password=Password1) => {"backup": "", "changed": false, "item": "password=Password1", "msg": ""}
TASK [Making database] *********************************************************
task path: /home/centos/.ansible/centos-mariadb.playbook:36
ok: [172.30.1.21] => {"changed": false, "db": "tests"}
ok: [172.30.1.38] => {"changed": false, "db": "tests"}
TASK [Making replication user] *************************************************
task path: /home/centos/.ansible/centos-mariadb.playbook:38
fatal: [172.30.1.21]: FAILED! => {"changed": false, "failed": true, "msg": "(1045, \"Access denied for user 'root'@'localhost' (using password: YES)\")"}
fatal: [172.30.1.38]: FAILED! => {"changed": false, "failed": true, "msg": "(1045, \"Access denied for user 'root'@'localhost' (using password: YES)\")"}
NO MORE HOSTS LEFT *************************************************************
Conectar manualmente a partir do shell funciona bem:
$ sudo mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.50-MariaDB MariaDB Server