Skip to content

Commit

Permalink
fix: use the right systemd service for remediations in EL 10+
Browse files Browse the repository at this point in the history
EL 10 has a newer yggdrasil service for remediations, so instead of
'rhcd' the upstream name 'yggdrasil' is used.

Hence:
- create an helper variable for the service name depending on the EL
  version; since Insights is specific to RHEL, it is possible to assume
  the name based on the major version of the distribution
- use the new variable when enabling or disabling the service for
  remediations
- in the test case for remediation:
  - export the variables of the role as public, so the new private
    variable can be used
  - set an helper fact with the systemd service including the '.service'
    extension

Fixes: CCT-1057

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
  • Loading branch information
ptoscano authored and richm committed Jan 24, 2025
1 parent c79ba27 commit 1d23e90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tasks/insights-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@
systemd:
enabled: true
state: started
name: rhcd
name: "{{ __rhc_yggdrasil_systemd_service }}"

- name: Disable remediation
systemd:
enabled: false
state: stopped
name: rhcd
name: "{{ __rhc_yggdrasil_systemd_service }}"
when:
- rhc_insights.remediation | d("present") == "absent"
- '"rhc" in ansible_facts.packages'
13 changes: 9 additions & 4 deletions tests/tests_insights_remediation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- name: Register insights and enable remediation
include_role:
name: linux-system-roles.rhc
public: true
vars:
rhc_auth:
login:
Expand All @@ -41,14 +42,18 @@
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"

- name: Set the fact for the systemd service
set_fact:
yggdrasil_systemd_service: "{{ __rhc_yggdrasil_systemd_service + '.service' }}"

- name: Get service_facts
service_facts:

- name: Check remediation is enabled
assert:
that:
- "'rhcd.service' in ansible_facts.services"
- ansible_facts.services['rhcd.service'].status == 'enabled'
- yggdrasil_systemd_service in ansible_facts.services
- ansible_facts.services[yggdrasil_systemd_service].status == 'enabled'

- name: Disable remediation
include_role:
Expand All @@ -63,8 +68,8 @@
- name: Check remediation is disabled
assert:
that:
- "'rhcd.service' in ansible_facts.services"
- ansible_facts.services['rhcd.service'].status == 'disabled'
- yggdrasil_systemd_service in ansible_facts.services
- ansible_facts.services[yggdrasil_systemd_service].status == 'disabled'

- name: Disable remediation (noop)
include_role:
Expand Down
7 changes: 7 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ __rhc_insights_conf: "/etc/insights-client/insights-client.conf"

__rhc_insights_tags: "/etc/insights-client/tags.yaml"

# name of the rhcd/yggdrasil systemd service that maintains the mqtt connection
# to Insights, used for remediations; starting from EL 10 the service is the
# upstream one, and no more the downstream-branded one
__rhc_yggdrasil_systemd_service: "{{ 'yggdrasil'
if (ansible_distribution_major_version | int >= 10)
else 'rhcd' }}"

# BEGIN - DO NOT EDIT THIS BLOCK - rh distros variables
# Ansible distribution identifiers that the role treats like RHEL
__rhc_rh_distros:
Expand Down

0 comments on commit 1d23e90

Please sign in to comment.