Joined April 2013
·

Dennis Jacobfeuerborn

Erkrath, Germany
·
·

Posted to Secure mysql with ansible over 1 year ago

This can be simplified by updating all root passwords with one action but making sure that 'localhost' is the last entry. That way the second invocation of the password changing action can be eliminated:

- name: MySQL setup
  hosts: dbservers
  gather_facts: True
  tasks:

    # 'localhost' needs to be the last item for idempotency, see
    # http://ansible.cc/docs/modules.html#mysql-user
    - 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

    - name: copy .my.cnf file with root password credentials
      template: src=templates/root/.my.cnf dest=/root/.my.cnf owner=root mode=0600

    - name: ensure anonymous users are not in the database
      mysql_user: name='' host=$item state=absent
      with_items:
        - localhost
        - $inventory_hostname

    - name: remove the test database
      mysql_db: name=test state=absent
Achievements
11 Karma
0 Total ProTip Views
Interests & Skills