Skip to content

Commit

Permalink
Add Rocky support
Browse files Browse the repository at this point in the history
  • Loading branch information
mamedin committed Oct 12, 2023
1 parent 3c73f6e commit 80b731f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 18 deletions.
5 changes: 3 additions & 2 deletions tasks/check-settings-centos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

- name: "Check if percona-server is installed"
shell: rpm -qa | grep -i percona-server-server
ignore_errors: yes
failed_when: false
changed_when: false
check_mode: false
register: percona_server_is_installed
changed_when: False

- name: "Check for innodb_log_file_size setting (RedHat/CentOS)"
shell:
Expand Down
5 changes: 3 additions & 2 deletions tasks/check-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

- name: "Check if percona-server is installed"
shell: dpkg -l | grep -i percona-server-server
ignore_errors: yes
failed_when: false
changed_when: false
check_mode: false
register: percona_server_is_installed
changed_when: False

- name: "Check for innodb_log_file_size setting (Ubuntu)"
shell:
Expand Down
2 changes: 1 addition & 1 deletion tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
collation: "{{ item.collation | default('utf8_general_ci') }}"
encoding: "{{ item.encoding | default('utf8') }}"
state: "present"
login_unix_socket: "{% if ansible_os_family == 'RedHat' %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
login_unix_socket: "{% if ansible_os_family in ['RedHat','Rocky'] %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
with_items: "{{ mysql_databases }}"

- name: "Load timezone database into MySQL"
Expand Down
33 changes: 31 additions & 2 deletions tasks/install-centos.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
---
- name: "Disable local mysql repo RedHat/CentOS/Rocky >= 8.0)"
command: "dnf module disable mysql -y"
when:
- ansible_distribution_major_version|int == 8
- install_rpm_repositories|bool

- name: "Remove mariadb-connector-c-config (RedHat/CentOS/Rocky >= 8.0)"
yum:
name:
- "mariadb-connector-c-config"
state: absent
when:
- ansible_distribution_version is version_compare('8.0', '>=')

- name: "Add Percona yum repository"
yum:
name: https://repo.percona.com/yum/percona-release-latest.noarch.rpm
Expand All @@ -7,10 +21,16 @@

# https://www.percona.com/doc/percona-server/LATEST/installation/yum_repo.html
- name: "Enable Percona repository (Percona version >= 8)"
command: "percona-release setup ps{{ mysql_version_major }}{{ mysql_version_minor }}"
command: "percona-release setup ps{{ mysql_version_major }}{{ mysql_version_minor }} -y"
when: mysql_version_major|int >= 8 and install_rpm_repositories|bool
changed_when: False # TODO: check for task idempotency

- name: "Enable Percona toolkit (RH/CentOS/Rocky >= 8.0)"
command: "percona-release enable tools"
when:
- install_rpm_repositories|bool
- ansible_distribution_version is version_compare('8.0', '>=')

- name: "Install percona database server (Percona version < 8)"
yum:
name:
Expand All @@ -31,10 +51,19 @@
state: present
when: mysql_version_major|int >= 8

- name: "Install MySQL-python package"
- name: "Install MySQL-python package (ansible python2)"
yum:
name: "MySQL-python"
state: present
when:
- ansible_python.version.major == 2 # version is a number, do not quote

- name: "Install MySQL-python package (ansible python3)"
yum:
name: "python3-PyMySQL"
state: present
when:
- ansible_python.version.major == 3 # version is a number, do not quote

- name: "Adjust permissions of datadir"
file:
Expand Down
12 changes: 6 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
- include: check-settings.yml
tags: check
when: ansible_os_family != "RedHat"
when: ansible_os_family not in ['RedHat', 'Rocky']

- include: check-settings-centos.yml
tags: check
when: ansible_os_family == "RedHat"
when: ansible_os_family in ['RedHat', 'Rocky']

- include: install.yml
tags: install
when: ansible_os_family != "RedHat"
when: ansible_os_family not in ['RedHat', 'Rocky']

- include: install-centos.yml
tags: install
when: ansible_os_family == "RedHat"
when: ansible_os_family in ['RedHat', 'Rocky']

- include: configure.yml
tags: configure
when: ansible_os_family != "RedHat"
when: ansible_os_family not in ['RedHat', 'Rocky']

- include: configure-centos.yml
tags: configure
when: ansible_os_family == "RedHat"
when: ansible_os_family in ['RedHat', 'Rocky']

- include: secure.yml
tags: secure
Expand Down
8 changes: 4 additions & 4 deletions tasks/secure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
register: root_my_cnf_stat
when:
- mysql_version is version('5.7', '>=')
- ansible_os_family == "RedHat"
- ansible_os_family in ['RedHat', 'Rocky']

- name: "Percona >= 5.7 new install measures (Red Hat)"
block:
Expand All @@ -29,7 +29,7 @@
mode: 0600
when:
- mysql_version is version('5.7', '>=')
- ansible_os_family == "RedHat"
- ansible_os_family in ['RedHat', 'Rocky']
- root_my_cnf_stat.stat.exists == False

- name: "Set the root password"
Expand All @@ -39,7 +39,7 @@
password: "{{ mysql_root_password }}"
check_implicit_admin: yes
state: present
login_unix_socket: "{% if ansible_os_family == 'RedHat' %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
login_unix_socket: "{% if ansible_os_family in ['RedHat', 'Rocky'] %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"

with_items:
- "{{ ansible_hostname }}"
Expand All @@ -60,7 +60,7 @@
name: ''
host: "{{ item }}"
state: absent
login_unix_socket: "{% if ansible_os_family == 'RedHat' %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
login_unix_socket: "{% if ansible_os_family in ['RedHat', 'Rocky'] %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
with_items:
- "{{ ansible_hostname }}"
- "localhost"
Expand Down
2 changes: 1 addition & 1 deletion tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
priv: "{{ item.priv | default('*.*:ALL') }}"
state: "present"
host: "{{ item.host | default('localhost') }}"
login_unix_socket: "{% if ansible_os_family == 'RedHat' %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
login_unix_socket: "{% if ansible_os_family in ['RedHat', 'Rocky'] %}/var/lib/mysql/mysql.sock{% else %}/var/run/mysqld/mysqld.sock{% endif %}"
with_items: "{{ mysql_users }}"
no_log: "true"

0 comments on commit 80b731f

Please sign in to comment.