Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Issue with pipeline service mysql and ansible connection

(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

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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,749 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you