Commit bf86dbf1 authored by Ing. Matej Madeja's avatar Ing. Matej Madeja
Browse files

database config

parent 3dd3da9e
---
# tasks file for mariadb-config
tasks file for mariadb-config
- name: Install phpmyadmin and dependencies
apt:
pkg:
......@@ -21,29 +21,60 @@
insertafter: "EOF"
notify: restart apache
# command will execute only if `/root/.my.cnf` does not exist
- name: "Generate new password"
shell: "openssl rand -hex 7"
become: yes
shell:
cmd: "openssl rand -hex 7"
creates: /root/.my.cnf
register: mysql_new_root_pass
- name: "Create my.cnf file for root"
become: yes
template:
src: mysql/my.cnf.j2
dest: /root/.my.cnf
when: mysql_new_root_pass.changed
- debug:
var: mysql_new_root_pass
# dependency of `mysql_user` module
- name: "Install PyMySQL"
become: yes
pip:
name: PyMySQL
- name: "Change password for root"
become: yes
mysql_user:
name: root
password: "{{ mysql_new_root_pass.stdout }}"
priv: '*.*:ALL'
host: "{{ item }}"
state: present
with_items:
- 127.0.0.1
- ::1
- localhost
- "{{ ansible_hostname }}"
# this task not working because of some dependencies problems
# - name: Update root password
# become: yes
# mysql_user:
# name: root
# host: "{{ item }}"
# password: "{{mysql_new_root_pass.stdout }}"
# with_items:
# - "{{ ansible_hostname }}"
# - 127.0.0.1
# - ::1
# - localhost
# when: mysql_new_root_pass.changed
# print only if root password was not generated
- debug:
msg: "Password was not changed"
when: not mysql_new_root_pass.changed
[client]
user=root
password="{{ mysql_new_root_pass.stdout }}"
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment