Skip to content

Commit

Permalink
Address fqcn linter rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 12, 2023
1 parent ddd9c29 commit 282f03d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: restart mysql
service:
ansible.builtin.service:
name: "{{ mysql_daemon }}"
state: restarted
sleep: 5
4 changes: 2 additions & 2 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

post_tasks:
- name: Make sure we can connect to MySQL via Unix socket.
command: "mysql -u root -proot -e 'show databases;'"
ansible.builtin.command: "mysql -u root -proot -e 'show databases;'"
changed_when: false

- name: Make sure we can connect to MySQL via TCP.
command: "mysql -u root -proot -h 127.0.0.1 -e 'show databases;'"
ansible.builtin.command: "mysql -u root -proot -h 127.0.0.1 -e 'show databases;'"
changed_when: false
20 changes: 10 additions & 10 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Get MySQL version.
command: 'mysql --version'
ansible.builtin.command: 'mysql --version'
register: mysql_cli_version
changed_when: false
check_mode: false

- name: Copy my.cnf global MySQL configuration.
template:
ansible.builtin.template:
src: my.cnf.j2
dest: "{{ mysql_config_file }}"
owner: root
Expand All @@ -16,7 +16,7 @@
notify: restart mysql

- name: Verify mysql include directory exists.
file:
ansible.builtin.file:
path: "{{ mysql_config_include_dir }}"
state: directory
owner: root
Expand All @@ -25,7 +25,7 @@
when: mysql_config_include_files | length

- name: Copy my.cnf override files into include directory.
template:
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ mysql_config_include_dir }}/{{ item.src | basename }}"
owner: root
Expand All @@ -36,13 +36,13 @@
notify: restart mysql

- name: Create slow query log file (if configured).
command: "touch {{ mysql_slow_query_log_file }}"
ansible.builtin.command: "touch {{ mysql_slow_query_log_file }}"
args:
creates: "{{ mysql_slow_query_log_file }}"
when: mysql_slow_query_log_enabled

- name: Create datadir if it does not exist
file:
ansible.builtin.file:
path: "{{ mysql_datadir }}"
state: directory
owner: mysql
Expand All @@ -51,7 +51,7 @@
setype: mysqld_db_t

- name: Set ownership on slow query log file (if configured).
file:
ansible.builtin.file:
path: "{{ mysql_slow_query_log_file }}"
state: file
owner: mysql
Expand All @@ -60,7 +60,7 @@
when: mysql_slow_query_log_enabled

- name: Create error log file (if configured).
command: "touch {{ mysql_log_error }}"
ansible.builtin.command: "touch {{ mysql_log_error }}"
args:
creates: "{{ mysql_log_error }}"
when:
Expand All @@ -69,7 +69,7 @@
tags: ['skip_ansible_galaxy']

- name: Set ownership on error log file (if configured).
file:
ansible.builtin.file:
path: "{{ mysql_log_error }}"
state: file
owner: mysql
Expand All @@ -81,7 +81,7 @@
tags: ['skip_ansible_galaxy']

- name: Ensure MySQL is started and enabled on boot.
service:
ansible.builtin.service:
name: "{{ mysql_daemon }}"
state: started
enabled: "{{ mysql_enabled_on_startup }}"
Expand Down
20 changes: 10 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
# Variable configuration.
- include_tasks: variables.yml
- ansible.builtin.include_tasks: variables.yml

# Setup/install tasks.
- include_tasks: setup-RedHat.yml
- ansible.builtin.include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'

- include_tasks: setup-Debian.yml
- ansible.builtin.include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'

- include_tasks: setup-Archlinux.yml
- ansible.builtin.include_tasks: setup-Archlinux.yml
when: ansible_os_family == 'Archlinux'

- name: Check if MySQL packages were installed.
set_fact:
ansible.builtin.set_fact:
mysql_install_packages: "{{ (rh_mysql_install_packages is defined and rh_mysql_install_packages.changed)
or (deb_mysql_install_packages is defined and deb_mysql_install_packages.changed)
or (arch_mysql_install_packages is defined and arch_mysql_install_packages.changed) }}"

# Configure MySQL.
- include_tasks: configure.yml
- include_tasks: secure-installation.yml
- include_tasks: databases.yml
- include_tasks: users.yml
- include_tasks: replication.yml
- ansible.builtin.include_tasks: configure.yml
- ansible.builtin.include_tasks: secure-installation.yml
- ansible.builtin.include_tasks: databases.yml
- ansible.builtin.include_tasks: users.yml
- ansible.builtin.include_tasks: replication.yml
14 changes: 7 additions & 7 deletions tasks/secure-installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Has to be after the password assignment, for idempotency.
- name: Copy user-my.cnf file with password credentials.
template:
ansible.builtin.template:
src: "user-my.cnf.j2"
dest: "{{ mysql_user_home }}/.my.cnf"
owner: "{{ mysql_user_name }}"
Expand All @@ -20,13 +20,13 @@
and (mysql_install_packages | bool or mysql_user_password_update)
- name: Disallow root login remotely
command: 'mysql -NBe "{{ item }}"'
ansible.builtin.command: 'mysql -NBe "{{ item }}"'
with_items:
- DELETE FROM mysql.user WHERE User='{{ mysql_root_username }}' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
changed_when: false

- name: Get list of hosts for the root user.
command: mysql -NBe
ansible.builtin.command: mysql -NBe
"SELECT Host
FROM mysql.user
WHERE User = '{{ mysql_root_username }}'
Expand All @@ -40,7 +40,7 @@
# the root password correctly. See: https://goo.gl/MSOejW
# Set root password for MySQL >= 5.7.x.
- name: Update MySQL root password for localhost root account (5.7.x).
shell: >
ansible.builtin.shell: >
mysql -u root -NBe
"ALTER USER '{{ mysql_root_username }}'@'{{ item }}'
IDENTIFIED WITH mysql_native_password BY '{{ mysql_root_password }}'; FLUSH PRIVILEGES;"
Expand All @@ -51,7 +51,7 @@
# Set root password for MySQL < 5.7.x.
- name: Update MySQL root password for localhost root account (< 5.7.x).
shell: >
ansible.builtin.shell: >
mysql -NBe
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}"); FLUSH PRIVILEGES;'
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
Expand All @@ -61,7 +61,7 @@
# Has to be after the root password assignment, for idempotency.
- name: Copy .my.cnf file with root password credentials.
template:
ansible.builtin.template:
src: "root-my.cnf.j2"
dest: "{{ mysql_root_home }}/.my.cnf"
owner: root
Expand All @@ -70,7 +70,7 @@
when: mysql_install_packages | bool or mysql_root_password_update

- name: Get list of hosts for the anonymous user.
command: mysql -NBe "SELECT Host FROM mysql.user WHERE User = ''"
ansible.builtin.command: mysql -NBe "SELECT Host FROM mysql.user WHERE User = ''"
register: mysql_anonymous_hosts
changed_when: false
check_mode: false
Expand Down
6 changes: 3 additions & 3 deletions tasks/setup-Archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Ensure MySQL Python libraries are installed.
pacman: "name=mysql-python state=present"
community.general.pacman: "name=mysql-python state=present"

- name: Ensure MySQL packages are installed.
pacman: "name={{ mysql_packages }} state=present"
community.general.pacman: "name={{ mysql_packages }} state=present"
register: arch_mysql_install_packages

- name: Run mysql_install_db if MySQL packages were changed.
command: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
ansible.builtin.command: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
when: arch_mysql_install_packages.changed
tags: ['skip_ansible_lint']
12 changes: 6 additions & 6 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
- name: Check if MySQL is already installed.
stat:
ansible.builtin.stat:
path: "{{ mysql_config_file }}"
register: mysql_installed

- name: Update apt cache if MySQL is not yet installed.
apt: update_cache=yes
ansible.builtin.apt: update_cache=yes
changed_when: False
when: not mysql_installed.stat.exists

- name: Ensure MySQL Python libraries are installed.
apt:
ansible.builtin.apt:
name: "{{ mysql_python_package_debian }}"
state: present

- name: Ensure MySQL packages are installed.
apt:
ansible.builtin.apt:
name: "{{ mysql_packages }}"
state: present
policy_rc_d: 101
Expand All @@ -24,11 +24,11 @@
# Because Ubuntu starts MySQL as part of the install process, we need to stop
# mysql and remove the logfiles in case the user set a custom log file size.
- name: Ensure MySQL is stopped after initial install.
service: "name={{ mysql_daemon }} state=stopped"
ansible.builtin.service: "name={{ mysql_daemon }} state=stopped"
when: not mysql_installed.stat.exists

- name: Delete innodb log files created by apt package after initial install.
file:
ansible.builtin.file:
path: "{{ mysql_datadir }}/{{ item }}"
state: absent
with_items:
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure MySQL packages are installed.
yum:
ansible.builtin.yum:
name: "{{ mysql_packages }}"
state: present
enablerepo: "{{ mysql_enablerepo | default(omit, true) }}"
Expand Down
22 changes: 11 additions & 11 deletions tasks/variables.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
---
# Variable configuration.
- name: Include OS-specific variables.
include_vars: "{{ item }}"
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- files:
- "vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "vars/{{ ansible_os_family }}.yml"
skip: true

- name: Define mysql_packages.
set_fact:
ansible.builtin.set_fact:
mysql_packages: "{{ __mysql_packages | list }}"
when: mysql_packages is not defined

- name: Define mysql_daemon.
set_fact:
ansible.builtin.set_fact:
mysql_daemon: "{{ __mysql_daemon }}"
when: mysql_daemon is not defined

- name: Define mysql_slow_query_log_file.
set_fact:
ansible.builtin.set_fact:
mysql_slow_query_log_file: "{{ __mysql_slow_query_log_file }}"
when: mysql_slow_query_log_file is not defined

- name: Define mysql_log_error.
set_fact:
ansible.builtin.set_fact:
mysql_log_error: "{{ __mysql_log_error }}"
when: mysql_log_error is not defined

- name: Define mysql_syslog_tag.
set_fact:
ansible.builtin.set_fact:
mysql_syslog_tag: "{{ __mysql_syslog_tag }}"
when: mysql_syslog_tag is not defined

- name: Define mysql_pid_file.
set_fact:
ansible.builtin.set_fact:
mysql_pid_file: "{{ __mysql_pid_file }}"
when: mysql_pid_file is not defined

- name: Define mysql_config_file.
set_fact:
ansible.builtin.set_fact:
mysql_config_file: "{{ __mysql_config_file }}"
when: mysql_config_file is not defined

- name: Define mysql_config_include_dir.
set_fact:
ansible.builtin.set_fact:
mysql_config_include_dir: "{{ __mysql_config_include_dir }}"
when: mysql_config_include_dir is not defined

- name: Define mysql_socket.
set_fact:
ansible.builtin.set_fact:
mysql_socket: "{{ __mysql_socket }}"
when: mysql_socket is not defined

- name: Define mysql_supports_innodb_large_prefix.
set_fact:
ansible.builtin.set_fact:
mysql_supports_innodb_large_prefix: "{{ __mysql_supports_innodb_large_prefix }}"
when: mysql_supports_innodb_large_prefix is not defined

0 comments on commit 282f03d

Please sign in to comment.