|
| 1 | +--- |
| 2 | + |
| 3 | +# supported for ansible ver => 2.0 |
| 4 | +#- name: Install python-mysqldb for Ansible |
| 5 | +# package: pkg=python-mysqldb state=present |
| 6 | + |
| 7 | + |
| 8 | +- name: Install MySQL-python for Ansible |
| 9 | + apt: name=python-mysqldb state=present |
| 10 | + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' |
| 11 | + |
| 12 | +- name: Install python-mysqldb for Ansible |
| 13 | + yum: name=MySQL-python state=present |
| 14 | + when: ansible_os_family == 'RedHat' or ansible_os_family == 'Oracle Linux' |
| 15 | + |
| 16 | +- debug: msg="WARNING - you have to change default mysql_root_password" |
| 17 | + when: mysql_root_password == '-----====>SetR00tPa$$wordH3r3!!!<====-----' |
| 18 | + |
| 19 | +- name: root password is present |
| 20 | + mysql_user: name=root host={{item}} password={{mysql_root_password | mandatory}} state=present |
| 21 | + with_items: |
| 22 | + - '::1' |
| 23 | + - '127.0.0.1' |
| 24 | + - 'localhost' |
| 25 | + |
| 26 | +- name: install .my.cnf with credentials |
| 27 | + template: src=my.cnf.j2 dest={{mysql_user_home}}/.my.cnf |
| 28 | + mode=0400 |
| 29 | + tags: my_cnf |
| 30 | + |
| 31 | +- name: test database is absent |
| 32 | + mysql_db: name=test state=absent |
| 33 | + when: mysql_remove_test_database |
| 34 | + |
| 35 | +# Can use only if ansible ver => 2.1 |
| 36 | +#- name: anonymous users are absent |
| 37 | +# mysql_user: name='' state=absent host_all=yes |
| 38 | +# when: mysql_remove_anonymous_users |
| 39 | + |
| 40 | +- name: copy mysql_remove_anonymous_users |
| 41 | + copy: src='{{item}}.sql' dest='/tmp/{{item}}.sql' |
| 42 | + with_items: |
| 43 | + - mysql_remove_anonymous_users |
| 44 | + when: mysql_remove_anonymous_users |
| 45 | + changed_when: false |
| 46 | + |
| 47 | +- name: apply mysql_remove_anonymous_users |
| 48 | + mysql_db: name='mysql' state=import target='/tmp/{{item}}.sql' |
| 49 | + with_items: |
| 50 | + - mysql_remove_anonymous_users |
| 51 | + when: mysql_remove_anonymous_users |
| 52 | + changed_when: false |
| 53 | + |
| 54 | +- name: copy mysql_remove_remote_root |
| 55 | + copy: src='{{item}}.sql' dest='/tmp/{{item}}.sql' |
| 56 | + with_items: |
| 57 | + - mysql_remove_remote_root |
| 58 | + when: mysql_remove_remote_root |
| 59 | + changed_when: false |
| 60 | + |
| 61 | +- name: apply mysql_remove_remote_root |
| 62 | + mysql_db: name='mysql' state=import target='/tmp/{{item}}.sql' |
| 63 | + with_items: |
| 64 | + - mysql_remove_remote_root |
| 65 | + when: mysql_remove_remote_root |
| 66 | + changed_when: false |
0 commit comments