Issue with pipeline service mysql and ansible connection

AS November 6, 2020

(I'm sorry I couldnt work out how to pase code into the code block, and retain its formatting. Ive cleaned up where needed to make readable)

Basically, I can not get ansible to connect and create a user. Tried a few different options, but I always get back to some variation of:

unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials.
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

 

definitions:
services:
mysql:
image: mysql:5.7
variables:
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'test_user'
MYSQL_PASSWORD: 'test_user_password'

pipelines:
default:
- parallel:
- step:
name: test
services:
- mysql

script:
- apt-get update && apt-get install -y mysql-client
- mysql -h 127.0.0.1 -u test_user -ptest_user_password -e "SHOW DATABASES"
- ansible-playbook ci.yml -i hosts --connection=local

 

The SHOW DATABASES line works.

However, when the ansible playbook gets to my task:


- name: add dev user to database
mysql_user:
  name: '{{backend_database.user}}'
  password: '{{backend_database.pass}}'
  login_password: 'test_user_password'
  login_user: 'test_user'
  host: '{{backend_database.address}}'
  priv: '*.*:ALL'
  state: present
become: true

 I always get the error above.

I've tried so many combinations of things and always fails here.
Includingm adding to the ansible task:


login_unix_socket: '/var/run/mysqld/mysqld.sock'
login_unix_socket: /var/lib/mysql/mysql.sock


Any pointers or advice on things to look into would be greatly appreciated. I'm very confused at what I'm missing here.

To be clear, this works locally on my vagrant box.

I've seen this similar error before when there is no mysql-server running, but I assume the working SHOW DATABASES proves there is a mysql server running?

Cheers for any help.

1 answer

0 votes
AS November 6, 2020

Ok, I missed one variable from the ansible docks that helped here:

login_host: default is localhost


- name: add dev user to database
mysql_user:
name: '{{backend_database.user}}'
password: '{{backend_database.pass}}'
login_host: '{{backend_database.address}}'
host: '{{backend_database.address}}'
priv: '*.*:ALL'
state: present
become: true

 

Hopefully this helps others coming up against the socket error.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events