Hello all,
I am new to ansible and I am attempting build my server stack using it. I am at the point where I am trying to change the root password for mysql and flush the privileges but am having a hard time getting this to work.
I have seen cases where people have copied over a my.cnf file into the users directory to change the root password while others have changed it by logging into mysql. I don't know the benefits / difference to doing one or the other. I simply prefer to not have to transfer a file if I can get away with it.
My code seems to execute without any errors but the mysql server password is not changed. I am wondering what I am overlooking.
Here is currently what my code looks like (code is to provision the latest version Ubuntu version) :
Code:
---
- hosts: web
remote_user: deploy
sudo: yes
vars:
rails_env: "{{RAILS_ENV | default(development)}}"
root_db_password: "{{ROOT_DB_PASS}}"
tasks:
- name: update system cache
apt: update_cache=yes
- name: Install MySQL
apt:
pkg: mysql-server
state: present
tags:
-mysql
- name: Install MySQL Dev Headers
apt:
pkg: libmysqld-dev
state: installed
tags:
- mysql
- name: Ensure Mysql is started
service:
name: mysql
state: started
enabled: true
tags:
- mysql
- name: Install Python MySQL module
apt:
pkg: python-mysqldb
state: installed
tags:
- mysql
- name: update mysql root password for all root accounts
mysql_user: name=root host=$item password=$root_db_password
with_items:
- $ansible_hostname
- 127.0.0.1
- ::1
- localhost
tags:
- mysql
- name: ensure anonymous users are not in the database
mysql_user: name='' host=$item state=absent
with_items:
- localhost
- $inventory_hostname
tags:
- mysql
- name: remove the test database
mysql_db: name=test state=absent
notify:
- restart mysql
tags:
- mysql
handlers:
- name: restart mysql
action: service name=mysql state=restarted enabled=yes