Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - name: Set listing address
- ini_file:
- dest: /etc/mysql/percona-server.conf.d/mysqld.cnf
- section: mysqld
- option: bind-address
- value: 0.0.0.0
- - name: Check if /root/.my.cnf exists
- state:
- path: /root/.my.cnf
- register: mycnf
- - block:
- - name: Generate root password
- shell: tr -d -c "a-zA-Z0-9" < /dev/urandom | head -c 20
- register: root_password
- - name: Save /root/.my.cnf
- blockinfile:
- dest: /root/.my.cnf
- create: yes
- block: |
- [mysql]
- user=root
- password={{ root_password.stdout }}
- - name: Save /root/.my.cnf in app servers
- blockinfile:
- dest: /root/.my.cnf
- block: |
- [mysql]
- user=root
- password={{ root_password.stdout }}
- host={{ ansible_eth1.ipv4.address }}
- create: yes
- delegate_to: "{{ item }}"
- delegate_facts: True
- with_items: "{{ appservers }}"
- - name: Update MySQL root password
- mysql_user: name=root host={{ item }} password={{ root_password.stdout }} check_implicit_admin=yes
- with_items:
- - "{{ ansible_hostname }}"
- - "127.0.0.1"
- - "localhost"
- ignore_errors: yes
- - name: Ensure anonymous users are not in the database
- mysql_user: name='' host={{ item }} state=absent login_user=root login_password={{ root_password.stdout }}
- with_items:
- - "{{ ansible_hostname }}"
- - "127.0.0.1"
- - "localhost"
- - "::1"
- ignore_errors: yes
- - name: Update MySQL root password
- mysql_user: name=root host={{ hostvars[item]['ansible_eth1']['ipv4']['address'] }} password={{ root_password.stdout }} login_user=root login_password={{ root_password.stdout }} check_implicit_admin=yes
- with_items: "{{ appservers }}"
- ignore_errors: yes
- when: mycnf.stat.islnk is not defined
- - name: "Mysql tune"
- synchronize:
- src: synchronize/
- dest: /
- notify: restart percona
- handlers:
- - name: "restart percona"
- service:
- name: mysqld
- state: restarted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement