Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.13 KB | None | 0 0
  1.  - name: Set listing address
  2.     ini_file:
  3.       dest: /etc/mysql/percona-server.conf.d/mysqld.cnf
  4.       section: mysqld
  5.       option: bind-address
  6.       value: 0.0.0.0
  7.  
  8.   - name: Check if /root/.my.cnf exists
  9.     state:
  10.       path: /root/.my.cnf
  11.     register: mycnf
  12.  
  13.   - block:
  14.     - name: Generate root password
  15.       shell: tr -d -c "a-zA-Z0-9" < /dev/urandom | head -c 20
  16.       register: root_password
  17.  
  18.     - name: Save /root/.my.cnf
  19.       blockinfile:
  20.         dest: /root/.my.cnf
  21.         create: yes
  22.         block: |
  23.          [mysql]
  24.           user=root
  25.           password={{ root_password.stdout }}
  26.  
  27.     - name: Save /root/.my.cnf in app servers
  28.       blockinfile:
  29.         dest: /root/.my.cnf
  30.         block: |
  31.          [mysql]
  32.           user=root
  33.           password={{ root_password.stdout }}
  34.           host={{ ansible_eth1.ipv4.address }}
  35.         create: yes
  36.       delegate_to: "{{ item }}"
  37.       delegate_facts: True
  38.       with_items: "{{ appservers }}"
  39.  
  40.     - name: Update MySQL root password
  41.       mysql_user: name=root host={{ item }} password={{ root_password.stdout }} check_implicit_admin=yes
  42.       with_items:
  43.        - "{{ ansible_hostname }}"
  44.         - "127.0.0.1"
  45.         - "localhost"
  46.       ignore_errors: yes
  47.  
  48.     - name: Ensure anonymous users are not in the database
  49.       mysql_user: name='' host={{ item }} state=absent login_user=root login_password={{ root_password.stdout }}
  50.       with_items:
  51.        - "{{ ansible_hostname }}"
  52.         - "127.0.0.1"
  53.         - "localhost"
  54.         - "::1"
  55.       ignore_errors: yes
  56.  
  57.     - name: Update MySQL root password
  58.       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
  59.       with_items: "{{ appservers }}"
  60.       ignore_errors: yes
  61.  
  62.   when: mycnf.stat.islnk is not defined
  63.  
  64.   - name: "Mysql tune"
  65.     synchronize:
  66.       src: synchronize/
  67.       dest: /
  68.     notify: restart percona
  69.  
  70.   handlers:
  71.     - name: "restart percona"
  72.       service:
  73.         name: mysqld
  74.         state: restarted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement