Skip to content
Snippets Groups Projects
Commit 81d99238 authored by jurgenhaas's avatar jurgenhaas
Browse files

ansible-playbooks/general#85 Linting [skip-ci]

parent b4f6b995
Branches
No related tags found
No related merge requests found
---
# file: roles/mysql/handlers/main.yml
- name: MySQL | Restart MySQL
service: name=mysql state=restarted
- name: Restart MySQL
service:
name: mysql
state: restarted
- name: MySQL | Restart MySQL 5.7
- name: Restart MySQL 5.7
systemd:
state: restarted
daemon_reload: yes
......
---
# file: roles/mysql/tasks/backup.yml
- name: MySQL | Backup | Configuration Directory
- name: Backup | Configuration Directory
file:
dest=/etc/automysqlbackup
owner=root
group=root
state=directory
mode='775'
dest: /etc/automysqlbackup
owner: root
group: root
state: directory
mode: 0775
- name: MySQL | Backup | Configuration File
- name: Backup | Configuration File
template:
src=automysqlbackup.conf
dest=/etc/automysqlbackup/automysqlbackup.conf
owner=root
group=root
mode='644'
src: automysqlbackup.conf
dest: /etc/automysqlbackup/automysqlbackup.conf
owner: root
group: root
mode: 0644
tags:
- backup
- name: MySQL | Backup | Script File
- name: Backup | Script File
copy:
src=automysqlbackup.sh
dest=/usr/local/bin/automysqlbackup.sh
owner=root
group=root
mode='755'
src: automysqlbackup.sh
dest: /usr/local/bin/automysqlbackup.sh
owner: root
group: root
mode: 0755
- name: MySQL | Backup | Cron Tab
- name: Backup | Cron Tab
cron:
name="MySQL Backup"
month='{{ mysqlbackup.cron.month|default(omit) }}'
day='{{ mysqlbackup.cron.day|default(omit) }}'
weekday='{{ mysqlbackup.cron.weekday|default(omit) }}'
hour='{{ mysqlbackup.cron.hour|default(omit) }}'
minute='{{ mysqlbackup.cron.minute|default(omit) }}'
job="/usr/local/bin/automysqlbackup.sh >>/var/log/mysql/backup.log 2>&1"
state={{ mysqlbackup.active|ternary('present', 'absent') }}
disabled='{{ crons_disabled|default(false) }}'
name: MySQL Backup
month: '{{ mysqlbackup.cron.month|default(omit) }}'
day: '{{ mysqlbackup.cron.day|default(omit) }}'
weekday: '{{ mysqlbackup.cron.weekday|default(omit) }}'
hour: '{{ mysqlbackup.cron.hour|default(omit) }}'
minute: '{{ mysqlbackup.cron.minute|default(omit) }}'
job: /usr/local/bin/automysqlbackup.sh >>/var/log/mysql/backup.log 2>&1
state: '{{ mysqlbackup.active|ternary("present", "absent") }}'
disabled: '{{ crons_disabled|default(false) }}'
tags:
- cron
---
# file: roles/mysql/tasks/install.yml
- name: MySQL | Install required packages
- name: Install required packages
apt:
pkg='mysql-server'
state='present'
pkg: mysql-server
state: present
# The following should also work for the new mechanism of MySQL 5.7 where
# the auth plugin for root@localhost is initially set to socket mode.
# This uses the pre-hashed default password 'root' which will then be changed
# afterwards if required.
- name: MySQL | Initially set root password for localhost
- name: Initially set root password for localhost
mysql_user:
user='root'
password='*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B'
host='localhost'
check_implicit_admin=yes
priv='*.*:ALL,GRANT'
login_unix_socket='/var/run/mysqld/mysqld.sock'
login_user='root'
encrypted='yes'
user: root
password: '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B'
host: localhost
check_implicit_admin: yes
priv: '*.*:ALL,GRANT'
login_unix_socket: /var/run/mysqld/mysqld.sock
login_user: root
encrypted: yes
- name: MySQL | Set real root password for localhost
- name: Set real root password for localhost
mysql_user:
user='root'
password='{{ mysql_root_password }}'
host='localhost'
check_implicit_admin=yes
priv='*.*:ALL,GRANT'
login_user='root'
login_password='root'
user: root
password: '{{ mysql_root_password }}'
host: localhost
check_implicit_admin: yes
priv: '*.*:ALL,GRANT'
login_user: root
login_password: root
when: mysql_root_password != 'root'
- name: MySQL | Set root password for all hosts
- name: Set root password for all hosts
mysql_user:
user='root'
password='{{ mysql_root_password }}'
host='{{ item }}'
append_privs=yes
priv='*.*:ALL,GRANT'
login_user='root'
login_password='{{ mysql_root_password }}'
user: root
password: '{{ mysql_root_password }}'
host: '{{ item }}'
append_privs: yes
priv: '*.*:ALL,GRANT'
login_user: root
login_password: '{{ mysql_root_password }}'
with_items:
- localhost
- 127.0.0.1
- ::1
- {{ inventory_hostname }}
ignore_errors: true
ignore_errors: yes
- name: MySQL | Create root .my.cnf file
- name: Create root .my.cnf file
ini_file:
dest='/root/.my.cnf'
create=yes
section='client'
option='{{ item.option }}'
value="'{{ item.value }}'"
dest: /root/.my.cnf
create: yes
section: client
option: '{{ item.option }}'
value: "'{{ item.value }}'"
with_items:
- option: user
value: root
......
......@@ -9,108 +9,112 @@
- block:
- name: MySQL | Check for initial installation requirement
shell: which mysqld
register: mysql_available
changed_when: false
failed_when: false
- import_tasks: install.yml
when: mysql_available.stdout == ''
- name: MySQL | Update required packages
apt:
pkg='{{ packages }}'
state=present
vars:
packages:
- mysql-server
- mytop
- name: MySQL | Check version
shell: mysqld --version
register: mysql_version
changed_when: false
failed_when: false
- name: MySQL | Configure server up to version 5.6
template:
src='etc-mysql-my-cnf'
dest='/etc/mysql/my.cnf'
owner='root'
group='root'
mode='644'
when: not mysql_version.stdout is match(".* Ver 5\.7.*")
notify: "MySQL | Restart MySQL"
- name: MySQL | Configure server version 5.7
template:
src='etc-mysql-mysql-conf-d-mysqld.cnf'
dest='/etc/mysql/mysql.conf.d/mysqld.cnf'
owner='root'
group='root'
mode='644'
when: mysql_version.stdout is match(".* Ver 5\.7.*")
notify: "MySQL | Restart MySQL 5.7"
- name: MySQL | Configure system services for server version 5.7
template:
src='etc-systemd-system-mysql.service'
dest='/etc/systemd/system/mysql.service'
owner='root'
group='root'
mode='644'
when: mysql_version.stdout is match(".* Ver 5\.7.*")
notify: "MySQL | Restart MySQL 5.7"
- name: MySQL | Configure mysqldump
template:
src='etc-mysql-conf-d-mysqldump.cnf'
dest='/etc/mysql/conf.d/mysqldump.cnf'
owner='root'
group='root'
mode='644'
- import_tasks: user.yml
- name: MySQL | Remove the MySQL test database
mysql_db:
db='test'
state='absent'
notify: "MySQL | Restart MySQL"
- import_tasks: master.yml
when: mysql_repl_master
- import_tasks: slave.yml
when: mysql_repl_slave
- import_tasks: backup.yml
tags:
- cron
- backup
- name: MySQL | Copy Tuning Scripts
copy:
src='{{ item }}'
dest='/usr/local/bin/{{ item }}'
owner=root
group=root
mode='755'
with_items:
- mysqltuner.pl
- tuning-primer.sh
- mysql-create-index.py
- pt-query-digest
- name: MySQL | Logrotate configuration
template:
src='etc-logrotate-d-mysql-server'
dest='/etc/logrotate.d/mysql-server'
owner=root
group=root
mode='644'
tags:
- logrotate
- name: Check for initial installation requirement
shell: which mysqld
register: mysql_available
changed_when: no
failed_when: no
- import_tasks: install.yml
when: mysql_available.stdout == ''
- name: Update required packages
apt:
pkg: '{{ packages }}'
state: present
vars:
packages:
- mysql-server
- mytop
- name: Check version
shell: mysqld --version
register: mysql_version
changed_when: no
failed_when: no
- name: Configure server up to version 5.6
template:
src: etc-mysql-my-cnf
dest: /etc/mysql/my.cnf
owner: root
group: root
mode: 0644
when: not mysql_version.stdout is match(".* Ver 5\.7.*")
notify:
- Restart MySQL
- name: Configure server version 5.7
template:
src: etc-mysql-mysql-conf-d-mysqld.cnf
dest: /etc/mysql/mysql.conf.d/mysqld.cnf
owner: root
group: root
mode: 0644
when: mysql_version.stdout is match(".* Ver 5\.7.*")
notify:
- Restart MySQL 5.7
- name: Configure system services for server version 5.7
template:
src: etc-systemd-system-mysql.service
dest: /etc/systemd/system/mysql.service
owner: root
group: root
mode: 0644
when: mysql_version.stdout is match(".* Ver 5\.7.*")
notify:
- Restart MySQL 5.7
- name: Configure mysqldump
template:
src: etc-mysql-conf-d-mysqldump.cnf
dest: /etc/mysql/conf.d/mysqldump.cnf
owner: root
group: root
mode: 644
- import_tasks: user.yml
- name: Remove the MySQL test database
mysql_db:
db: test
state: absent
notify:
- Restart MySQL
- import_tasks: master.yml
when: mysql_repl_master
- import_tasks: slave.yml
when: mysql_repl_slave
- import_tasks: backup.yml
tags:
- cron
- backup
- name: Copy Tuning Scripts
copy:
src: '{{ item }}'
dest: /usr/local/bin/{{ item }}
owner: root
group: root
mode: 0755
with_items:
- mysqltuner.pl
- tuning-primer.sh
- mysql-create-index.py
- pt-query-digest
- name: Logrotate configuration
template:
src: etc-logrotate-d-mysql-server
dest: /etc/logrotate.d/mysql-server
owner: root
group: root
mode: 0644
tags:
- logrotate
when: not excluded_roles or "mysql" not in excluded_roles
---
# file: roles/mysql/tasks/master.yml
- name: MySQL | Master | Define replication user and privileges
- name: Master | Define replication user and privileges
mysql_user:
user='repl'
password='{{mysql_repl_password}}'
host='{{item}}'
priv='*.*:REPLICATION SLAVE,REPLICATION CLIENT'
user: repl
password: '{{mysql_repl_password}}'
host: '{{item}}'
priv: '*.*:REPLICATION SLAVE,REPLICATION CLIENT'
with_items:
- "localhost"
- "127.0.0.1"
......
---
# file: roles/mysql/tasks/slave.yml
- name: MySQL | Slave | Status
- name: Slave | Status
debug: msg="Currently nothing to do yet"
---
# file: roles/mysql/tasks/user.yml
- name: MySQL | Set the root password for all other domains
- name: Set the root password for all other domains
mysql_user:
user='root'
password='{{ mysql_root_password }}'
host='{{ item }}'
check_implicit_admin=yes
user: root
password: '{{ mysql_root_password }}'
host: '{{ item }}'
check_implicit_admin: yes
with_items:
- localhost
- 127.0.0.1
- ::1
- {{ inventory_hostname }}
notify: "MySQL | Restart MySQL"
notify:
- Restart MySQL
- name: MySQL | Delete anonymous MySQL server user for all domains
- name: Delete anonymous MySQL server user for all domains
mysql_user:
user=''
host='{{ item }}'
state='absent'
user: ''
host: '{{ item }}'
state: absent
with_items:
- localhost
- 127.0.0.1
- ::1
- {{inventory_hostname}}
notify: "MySQL | Restart MySQL"
notify:
- Restart MySQL
- name: MySQL | Add external users
- name: Add external users
mysql_user:
user='{{ item.username }}'
password='{{ item.password }}'
host='%'
check_implicit_admin=yes
user: '{{ item.username }}'
password: '{{ item.password }}'
host: '%'
check_implicit_admin: yes
with_items: '{{ mysql_external_users|default([]) }}'
notify: "MySQL | Restart MySQL"
notify:
- Restart MySQL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment