Skip to content

Commit

Permalink
Add rockylinux9 to ci platform targets (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Nov 20, 2023
1 parent 94b5751 commit aa402f4
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
command: /lib/systemd/systemd
- name: debian11
command: /lib/systemd/systemd
- name: rockylinux9
command: /usr/lib/systemd/systemd
steps:
- name: Check out the codebase
uses: actions/checkout@v4
Expand Down
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mongos_package_name:
- mongodb-mongosh
- python3-pymongo
- python3-gnupg
- pkg-config
mongos_package_state: present
mongos_service_name: mongos
mongos_service_port: 27017
Expand All @@ -20,5 +19,3 @@ mongos_replicaset_config_name: config
mongos_replicaset_config_port: 27017
mongos_replicaset_config_members: []
mongos_replicaset_shards: []
mongos_user: mongodb
mongos_group: mongodb
47 changes: 40 additions & 7 deletions molecule/hold/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@
roles:
- nephelaiio.mongos
pre_tasks:
- name: Query package versions
- name: Query Debian package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ mongos_package_name }}"
register: _mongos_package_query
register: _debian_package_query
when: ansible_os_family == "Debian"
changed_when: false

- name: Initialize package versions
- name: Query RedHat package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ mongos_package_name }}"
register: _redhat_package_query
when: ansible_os_family == "RedHat"
changed_when: false

- name: Set package version facts
ansible.builtin.set_fact:
mongos_package_name: []
_mongos_package_query: "{{ _redhat_packages + _debian_packages }}"
vars:
_redhat_packages: "{{ [] if _redhat_package_query.skipped else _redhat_package_query.results }}"
_debian_packages: "{{ [] if _debian_package_query.skipped else _debian_package_query.results }}"

- name: Verify target package versions
ansible.builtin.fail:
Expand All @@ -24,10 +36,14 @@
_package: "{{ item.item }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _mongos_package_query.results }}"
loop: "{{ _mongos_package_query }}"
when: _stdout | length == 0

- name: Set target package versions
- name: Initialize package versions
ansible.builtin.set_fact:
mongos_package_name: []

- name: Set target Debian package versions
ansible.builtin.set_fact:
mongos_package_name: "{{ mongos_package_name + [_package] }}"
vars:
Expand All @@ -37,4 +53,21 @@
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _mongos_package_query.results }}"
loop: "{{ _mongos_package_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat package versions
ansible.builtin.set_fact:
mongos_package_name: "{{ mongos_package_name + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_target: "{{ (_stdout[0] if not _multiple else _stdout[1]).split(' ') }}"
_arch: "{{ _target[0].split('.')[1] }}"
_name: "{{ _target[0].split('.')[0] }}"
_version: "{{ _target[1] }}"
_package: "{{ _name }}-{{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _mongos_package_query }}"
when: ansible_os_family == "RedHat"
1 change: 0 additions & 1 deletion molecule/hold/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ provisioner:
- mongodb-org-server
- mongodb-org-mongos
- mongodb-mongosh
- pkg-config
scenario:
converge_sequence:
- converge
Expand Down
65 changes: 57 additions & 8 deletions molecule/hold/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,61 @@
hosts: mongos
become: true
tasks:
- name: Query package versions
- name: Query Debian package versions
ansible.builtin.shell:
cmd: "apt-cache madison {{ item }} | awk -F'|' '{ print $2 }'"
loop: "{{ mongos_package_name }}"
register: _mongos_package_query
register: _debian_package_query
when: ansible_os_family == 'Debian'
changed_when: false

- name: Query RedHat package versions
ansible.builtin.shell:
cmd: "yum list {{ item }} --showduplicates | grep '^{{ item }}' | awk '{ print $1,$2 }' | sort -r"
loop: "{{ mongos_package_name }}"
register: _redhat_package_query
when: ansible_os_family == "RedHat"
changed_when: false

- name: Set package version facts
ansible.builtin.set_fact:
_mongos_package_query: "{{ _redhat_packages + _debian_packages }}"
vars:
_redhat_packages: "{{ [] if _redhat_package_query.skipped else _redhat_package_query.results }}"
_debian_packages: "{{ [] if _debian_package_query.skipped else _debian_package_query.results }}"

- name: Initialize package versions
ansible.builtin.set_fact:
mongos_package_name: []
mongos_package_list: []

- name: Set target package versions
- name: Set target Debian package versions
ansible.builtin.set_fact:
mongos_package_name: "{{ mongos_package_name + [_package] }}"
mongos_package_list: "{{ mongos_package_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_version: "{{ _stdout[0] if not _multiple else _stdout[1] }}"
_package: "{{ item.item }}={{ _version | trim }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _mongos_package_query.results }}"
loop: "{{ _mongos_package_query }}"
when: ansible_os_family == "Debian"

- name: Set target RedHat package versions
ansible.builtin.set_fact:
mongos_package_list: "{{ mongos_package_list + [_package] }}"
vars:
_stdout: "{{ item.stdout_lines }}"
_multiple: "{{ _stdout | length > 1 }}"
_target: "{{ (_stdout[0] if not _multiple else _stdout[1]).split(' ') }}"
_arch: "{{ _target[0].split('.')[1] }}"
_name: "{{ _target[0].split('.')[0] }}"
_version: "{{ _target[1] }}"
_package: "{{ _name }}-{{ _version }}.{{ _arch }}"
loop_control:
label: "{{ item.item }}"
loop: "{{ _mongos_package_query }}"
when: ansible_os_family == "RedHat"

- name: Gather package facts
ansible.builtin.package_facts:
Expand All @@ -36,5 +69,21 @@
_package: "{{ item.split('=') | first }}"
_version: "{{ item.split('=') | last }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ mongos_package_name }}"
when: _package not in packages or _version != _installed
loop: "{{ mongos_package_list }}"
when:
- ansible_os_family == "Debian"
- _package not in packages or _version != _installed

- name: Verify package versions
ansible.builtin.fail:
msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}"
vars:
_prefix: "^{{ _package }}-"
_suffix: "-.*$"
_package: "{{ item.0 }}"
_version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}"
_installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}"
loop: "{{ mongos_package_name | zip(mongos_package_list) }}"
when:
- ansible_os_family == "RedHat"
- _package not in packages or _version != _installed
12 changes: 12 additions & 0 deletions tasks/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@
loop: "{{ _package_holds }}"
when: ansible_os_family == "Debian"
changed_when: false

- name: Configure yum package locks
community.general.yum_versionlock:
name: "{{ item.split('=') | first }}"
state: "{{ 'absent' if _lock_state == 'install' else 'present' }}"
vars:
_version_regex: ".*=.*"
_package_versions: "{{ [mongos_package_name] | flatten | map('regex_search', _version_regex) }}"
_package_holds: "{{ _package_versions | select('string') }}"
loop: "{{ _package_holds }}"
when: ansible_os_family == "RedHat"
changed_when: false
47 changes: 34 additions & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
---
- name: Release apt package holds
- name: Install package prerequisites for Debian systems
ansible.builtin.package:
name: pkg-config
state: present
when: ansible_os_family == "Debian"

- name: Install package prerequisites for RedHat systems
ansible.builtin.package:
name: yum-plugin-versionlock
state: present
when: ansible_os_family == "RedHat"

- name: Release package holds
ansible.builtin.include_tasks: lock.yml
vars:
_lock_state: hold
Expand All @@ -9,16 +21,24 @@
name: "{{ mongos_package_name }}"
state: "{{ mongos_package_state }}"

- name: Query systemd service location
ansible.builtin.command:
cmd: pkg-config systemd --variable=systemdsystemunitdir
changed_when: false
register: _systemd_query
tags: skip_ansible_lint
- name: Set systemd unit facts for Debian systems
when: ansible_os_family == 'Debian'
block:
- name: Query systemd service location
ansible.builtin.command:
cmd: pkg-config systemd --variable=systemdsystemunitdir
changed_when: false
register: _systemd_query
tags: skip_ansible_lint

- name: Record system service location
ansible.builtin.set_fact:
mongos_systemd_unit_location: "{{ _systemd_query.stdout }}"

- name: Record system service location
- name: Set systemd unit facts for RedHat systems
ansible.builtin.set_fact:
mongos_systemd_unit_location: "{{ _systemd_query.stdout }}"
mongos_systemd_unit_location: /etc/systemd/system
when: ansible_os_family == 'RedHat'

- name: Record mongos binary location
ansible.builtin.command:
Expand All @@ -33,20 +53,21 @@

- name: Create systemd configuration
ansible.builtin.template:
dest: "{{ _systemd_query.stdout }}/mongos.service"
dest: "{{ mongos_systemd_unit_location }}/mongos.service"
src: systemd.service.j2
owner: root
group: root
mode: 0644
vars:
_user: "{{ 'mongodb' if ansible_os_family == 'Debian' else 'mongod' }}"
_unit_exec_args: "--config {{ mongos_config_file }}"
_unit_config:
Unit:
After: network-online.target
Wants: network-online.target
Service:
User: "{{ mongos_user }}"
Group: "{{ mongos_group }}"
User: "{{ _user }}"
Group: "{{ _user }}"
ExecStart: "{{ _mongos_query.stdout }} {{ _unit_exec_args }}"
Type: simple
RuntimeDirectory: mongodb
Expand All @@ -69,7 +90,7 @@
ansible.builtin.include_tasks: service.yml
when: mongos_service_manage

- name: Configure apt package holds
- name: Configure package holds
ansible.builtin.include_tasks: lock.yml
vars:
_lock_state: install

0 comments on commit aa402f4

Please sign in to comment.