Skip to content

Instantly share code, notes, and snippets.

@tiabc
Created May 24, 2017 21:39
Show Gist options
  • Save tiabc/3a899f00df88589d4c674071f19198ea to your computer and use it in GitHub Desktop.
Save tiabc/3a899f00df88589d4c674071f19198ea to your computer and use it in GitHub Desktop.
Simple Percona5.7 Ansible playbook, solving mysql_user module error after upgrade to 5.7: "Your password has expired. To log in you must change it using a client that supports expired passwords."
---
- name: Install Percona yum repository
yum:
name: http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
state: present
notify: restart mysql
- name: Install Percona
yum:
name: "{{ item }}"
state: present
with_items:
- Percona-Server-server-57
- Percona-Server-devel-57
notify: restart mysql
- name: Install the Python MySQLB module
pip:
name: MySQL-python
- name: Ensure MySQL is up-and-running
service:
name: mysql
state: started
enabled: yes
- shell: cat /var/log/mysqld.log | grep "temporary password" | grep -oE '[^ ]+$'
register: tmp_root_password
- name: Detect and properly set root password
stat:
path: /root/.my.cnf
register: r
- mysql_user:
name: root
password: "{{ mysql_root_password }}"
when: r.stat.exists==True
- name: Set new password from temporary password
shell: 'mysql -e "SET PASSWORD = PASSWORD(''{{ mysql_root_password }}'');" --connect-expired-password -uroot -p"{{ tmp_root_password.stdout }}"'
when: r.stat.exists==False
# Now that the root password is set to the specified, make it default for the client.
- name: Copy my.cnf
template:
src: root_my.cnf.j2
dest: /root/.my.cnf
force: yes
- mysql_user:
name: "{{ mysql_user }}"
password: "{{ mysql_password }}"
priv: "{{ mysql_database }}.*:ALL"
state: present
- mysql_db:
name: "{{ mysql_database }}"
state: present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment