Browse Source

Woring :)

master
Blagovest Petrov 9 years ago
parent
commit
571d321d63
  1. 6
      tasks/main.yml
  2. 41
      tasks/mysql_secure_installation.yml
  3. 11
      tasks/ubuntu.yml

6
tasks/main.yml

@ -1,11 +1,5 @@
--- ---
- include: ubuntu.yml - include: ubuntu.yml
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '16.04'
- name: Add configuration
template: src={{ mysql_conf_tpl }} dest={{ mysql_conf_dir[ansible_distribution] }}/{{ mysql_conf_file }} owner=root group=root mode=0644
when: mysql_conf_tpl != 'change_me'
notify: restart mysql
- name: Start and enable service - name: Start and enable service
service: name=mysql state=started enabled=yes service: name=mysql state=started enabled=yes

41
tasks/mysql_secure_installation.yml

@ -3,34 +3,35 @@
# UPDATE mysql.user SET Password=PASSWORD('mysecret') WHERE User='root'; # UPDATE mysql.user SET Password=PASSWORD('mysecret') WHERE User='root';
# FLUSH PRIVILEGES; # FLUSH PRIVILEGES;
- name: Set root Password
mysql_user: name=root host={{ item }} password={{ mysql_root_password }} state=present
with_items:
- localhost
- 127.0.0.1
- ::1
- name: Reload privilege tables - name: Update database root password
command: 'mysql -ne "{{ item }}"' mysql_user:
with_items: name: 'root'
- FLUSH PRIVILEGES host: 'localhost'
changed_when: False password: '{{ mysql_root_password }}'
- name: Add .my.cnf - name: Create /root/.my.cnf file with root credentials
template: src=my.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0600 template:
src : 'my.cnf.j2'
dest : '/root/.my.cnf'
owner: 'root'
group: 'root'
mode : '0600'
- name: Remove anonymous users - name: Delete anonymous database user
command: 'mysql -ne "{{ item }}"' mysql_user:
with_items: user : ""
- DELETE FROM mysql.user WHERE User='' host : '{{ item }}'
changed_when: False state: 'absent'
with_items: [ '{{ ansible_hostname }}', 'localhost' ]
- name: Disallow root login remotely - name: Reload privilege tables
command: 'mysql -ne "{{ item }}"' command: 'mysql -ne "{{ item }}"'
with_items: with_items:
- DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1') - FLUSH PRIVILEGES
changed_when: False changed_when: False
- name: Remove test database and access to it - name: Remove test database and access to it
command: 'mysql -ne "{{ item }}"' command: 'mysql -ne "{{ item }}"'
with_items: with_items:

11
tasks/ubuntu.yml

@ -3,21 +3,14 @@
apt_key: apt_key:
state : 'present' state : 'present'
keyserver: 'keyserver.ubuntu.com' keyserver: 'keyserver.ubuntu.com'
id : '0xcbcb082a1bb943db' id : '0xF1656F24C74CD1D8'
- name: Setup MariaDB Repo - name: Setup MariaDB Repo
apt_repository: apt_repository:
repo: 'deb [arch=amd64,i386] http://ftp.hosteurope.de/mirror/mariadb.org/repo/10.1/ubuntu xenial main' repo: 'deb [arch=amd64,i386] http://ftp.hosteurope.de/mirror/mariadb.org/repo/10.1/ubuntu xenial main'
- name: Install MariaDB - name: Install MariaDB
apt: name=mariadb-server state=latest update_cache=yes apt: pkg={{ item }} state=present update_cache=yes
- name: Update apt cache
apt: update_cache=yes
when: mariadb_list.changed == True or mariadb_key.changed == True
- name: Install MariaDB
apt: pkg={{ item }} state=present
with_items: with_items:
- mariadb-server - mariadb-server
- mariadb-client - mariadb-client

Loading…
Cancel
Save