Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring lint back #17

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ on:
schedule:
- cron: '5 4 */14 * *' # Twice / month, at 4:05 AM.
jobs:
# lint:
# runs-on: ubuntu-20.04
# steps:
# - name: checkout
# uses: actions/checkout@v4
# - name: ansible-lint
# uses: ansible-community/ansible-lint-action@main
lint:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: ansible-lint
uses: ansible-community/ansible-lint-action@main
test:
# needs:
# - lint
needs:
- lint
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
config:
- image: "ubuntu"
tag: "latest" # latest == noble, as of this writing.
tag: "latest" # latest == noble, as of this writing.
- image: "ubuntu"
tag: "jammy"
# - image: "ubuntu"
# tag: "focal" # Service start times out in molecule tests. No idea why. :-(
# - image: "ubuntu" # Not testing focal, because the "service start"
# tag: "focal" # task times out in molecule tests, and nobody knows why.
steps:
- name: checkout
uses: actions/checkout@v4
Expand Down
8 changes: 2 additions & 6 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
---
- name: armdb restart mysql
service:
- name: ArMDB restart mysql
ansible.builtin.service:
name: mysql
state: restarted

- name: armdb systemctl daemon-reexec
ansible.builtin.systemd:
daemon_reexec: true
16 changes: 8 additions & 8 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ galaxy_info:
description: Installs MariaDB on Ubuntu
company: Acro Media Inc.
license: GPLv3
min_ansible_version: 2.0
min_ansible_version: '2.0'
platforms:
- name: Ubuntu
versions:
- focal
- jammy
- noble
galaxy_tags: []
dependencies: []
- name: Ubuntu
versions:
- focal
- jammy
- noble
galaxy_tags: [ ]
dependencies: [ ]
3 changes: 2 additions & 1 deletion molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Bootstrap
hosts: all
become: true
Expand All @@ -8,7 +9,7 @@
- name: Prepare
hosts: all
become: true
gather_facts: yes
gather_facts: true
tasks:
- name: Update cache
apt: update_cache=true cache_valid_time=600
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Check mariadb is configured
hosts: all
become: yes
become: true

tasks:

Expand Down
2 changes: 2 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
roles:
- name: robertdebock.bootstrap
collections:
- name: community.mysql
version: 3.9.0
141 changes: 74 additions & 67 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,100 +1,106 @@
- set_fact:
---
- name: Define the list of supported ubuntu versions
ansible.builtin.set_fact:
_supported_ubuntu_versions:
- '18.04'
- '20.04'
- '22.04'
- '24.04'

- name: Check if OS is Ubuntu LTS
assert:
ansible.builtin.assert:
that:
- ansible_distribution == 'Ubuntu'
- ansible_distribution_version in _supported_ubuntu_versions
fail_msg: Server must be Ubuntu LTS

- name: Check for existence of /root/.my.cnf
stat: path=/root/.my.cnf
ansible.builtin.stat:
path: /root/.my.cnf
register: root_my_cnf

- name: Fail when /root/.my.cnf doesn't exist, and no root password has been provided
fail:
ansible.builtin.fail:
msg: Could not read password from /root/.my.cnf. If this is the first time running your playbook, append ` --extra-vars mysql_root_password=$(openssl rand -base64 24) ` to your command line. Setting the mysql root password only needs to be done once.
when: root_my_cnf is defined
and root_my_cnf.stat is defined
and root_my_cnf.stat.exists == False
and (not root_my_cnf.stat.exists)
and mysql_root_password is not defined

- name: Install software-properties-common
apt:
ansible.builtin.apt:
name: software-properties-common
update_cache: true
state: present

- name: Apply apt config for explicitly specified MariaDB versions
block:
- name: Add apt key for MariaDB
apt_key:
keyserver: keyserver.ubuntu.com
id: F1656F24C74CD1D8
- name: Add apt repo for MariaDB
apt_repository:
repo: >
{{ mariadb_repo_deb_line }}
state: present
filename: mariadb
update_cache: true
tags:
- apt-repo
when: mariadb_version != 'auto'
block:
- name: Add apt key for MariaDB
ansible.legacy.apt_key:
keyserver: keyserver.ubuntu.com
id: F1656F24C74CD1D8

- name: Add apt repo for MariaDB
ansible.builtin.apt_repository:
repo: >
{{ mariadb_repo_deb_line }}
state: present
filename: mariadb
update_cache: true
tags:
- apt-repo

- name: Install MariaDB Server
apt:
when: not client_only
ansible.builtin.apt:
name: mariadb-server
state: present
update_cache: yes
when: client_only == false
update_cache: true

- name: Install MariaDB client
apt:
when: client_only
ansible.builtin.apt:
name: mariadb-client
state: present
update_cache: yes
when: client_only == true
update_cache: true

- name: Install python module
apt:
ansible.builtin.apt:
name:
- python3-mysqldb
state: present

- block:
- name: Install MariaDB Server
when: not client_only
block:
- name: Ensure mariadb service is running and starts on boot
service:
ansible.builtin.service:
name: mariadb
state: started
enabled: true

- 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: no
check_mode: false

- name: Remove anonymous MySQL users.
mysql_user:
name: ""
host: "{{ item }}"
state: absent
with_items: "{{ mysql_anonymous_hosts.stdout_lines|default([]) }}"
community.mysql.mysql_user:
name: ""
host: "{{ item }}"
state: absent
with_items: "{{ mysql_anonymous_hosts.stdout_lines | default([]) }}"

- name: Remove the test database
mysql_db:
community.mysql.mysql_db:
name: test
state: absent
ignore_errors: "{{ ansible_check_mode }}"

- name: Override default bind address
copy:
ansible.builtin.copy:
dest: "{{ mysql_include_dir }}/99-acromedia-bind-address.cnf"
content: |
[mysqld]
Expand All @@ -106,13 +112,14 @@
backup: false
when: mysql_bind_address != '127.0.0.1'
notify:
- armdb restart mysql
- ArMDB restart mysql

- debug:
- name: Debug mysql_allow_from
ansible.builtin.debug:
var: mysql_allow_from

- name: Give mysql root permission to run commands from places other than localhost (mysql_allow_from = scalar)
mysql_user:
community.mysql.mysql_user:
name: "{{ mysql_user }}"
priv: "*.*:ALL,GRANT"
append_privs: true
Expand All @@ -125,7 +132,7 @@
and mysql_allow_from != 'localhost'

- name: Give mysql root permission to run commands from places other than localhost (mysql_allow_from = list)
mysql_user:
community.mysql.mysql_user:
name: "{{ mysql_user }}"
priv: "*.*:ALL,GRANT"
append_privs: true
Expand All @@ -139,9 +146,8 @@
and mysql_allow_from |length > 0
with_items: "{{ mysql_allow_from }}"


- name: Update mysql root password
mysql_user:
community.mysql.mysql_user:
name: "{{ mysql_user }}"
host: "{{ item }}"
password: "{{ mysql_root_password }}"
Expand All @@ -152,56 +158,57 @@
- localhost
when: (root_my_cnf is defined
and root_my_cnf.stat is defined
and root_my_cnf.stat.exists == False)
or mysql_root_password is defined
and not root_my_cnf.stat.exists
) or mysql_root_password is defined
register: mysql_password_changed

when: client_only == false


- name: Save mysql root password credentials to /root/.my.cnf
template: src=root/my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600 backup=yes
ansible.builtin.template:
src: root/my.cnf.j2
dest: /root/.my.cnf
owner: root
mode: '0600'
backup: true
when: (
mysql_password_changed is defined
and mysql_password_changed is changed
mysql_password_changed is defined
and mysql_password_changed is changed
)
or (
client_only == true
and mysql_root_password is defined
client_only and mysql_root_password is defined
)

- name: Apply Acro's MariaDB 10.0 server config to Ubuntu 16.04
template:
when: ansible_distribution_version == '16.04'
and not client_only
ansible.builtin.template:
src: etc/mysql/conf.d/acro.cnf.j2
dest: /etc/mysql/conf.d/acro.cnf
owner: root
mode: 0644
backup: yes
backup: true
notify:
- armdb restart mysql
when: ansible_distribution_version == '16.04'
and client_only == false
- ArMDB restart mysql

- name: Apply MariaDB server customizations on Ubuntu >= 18.04
template:
when: ansible_distribution == 'Ubuntu' and
ansible_distribution_major_version|int >= 18
and not client_only
ansible.builtin.template:
src: etc/mysql/mariadb.conf.d/99-acromedia-server-overrides.cnf.j2
dest: "{{ mysql_include_dir }}/99-acromedia-server-overrides.cnf"
owner: root
group: root
mode: 0644
backup: yes
backup: true
notify:
- armdb restart mysql
when: ansible_distribution == 'Ubuntu' and
ansible_distribution_major_version|int >= 18
and client_only == false
- ArMDB restart mysql

- name: Apply MariaDB cient customizations on Ubuntu >= 18.04
template:
ansible.builtin.template:
src: etc/mysql/mariadb.conf.d/99-acromedia-client-overrides.cnf.j2
dest: "{{ mysql_include_dir }}/99-acromedia-client-overrides.cnf"
owner: root
mode: 0644
backup: yes
backup: true
when: ansible_distribution == 'Ubuntu' and
ansible_distribution_major_version|int >= 18