Skip to content

refactor: Refactor remediations - extract common code into role main - do not use fail/rescue#300

Merged
richm merged 1 commit intoredhat-cop:mainfrom
richm:refactor-remediations
Dec 2, 2025
Merged

refactor: Refactor remediations - extract common code into role main - do not use fail/rescue#300
richm merged 1 commit intoredhat-cop:mainfrom
richm:refactor-remediations

Conversation

@richm
Copy link
Collaborator

@richm richm commented Nov 26, 2025

There was a lot of code duplication in the remedation task files. This has been extracted
into the remediation role main task file.

The remediation tasks were using fail/rescue for flow control, which makes looking at the
logs very confusing, as you really have to know which tasks to exclude when looking for errors.
Instead, use plain old conditionals with blocks for tasks to run conditionally. NOTE: The
old way of using rescue would essentially catch and ignore all errors - this seems
wrong to me, but perhaps there is a reason. This means that now, remediation may raise
errors where before it would not.

Use ansible good practices:

  • Use vars instead of set_fact and keep the variables set at the lowest necessary scope
  • Use filters instead of loops
  • Use conditional evaluation instead of comparing a value == true
  • Use tests such as is success rather than looking at the register rc value directly

Signed-off-by: Rich Megginson rmeggins@redhat.com

@richm richm requested review from bontreger and spetrosi November 26, 2025 20:47
@richm
Copy link
Collaborator Author

richm commented Nov 26, 2025

@amott-rh https://github.com/redhat-cop/infra.leapp/pull/300/files#diff-1788d33239b6df3604a4164252101a7700ac2aa672847c342d39992157f11b19R149 - not sure if rhel6 is relevant anymore

@Monnte or @bontreger https://github.com/redhat-cop/infra.leapp/pull/300/files#diff-a3d91dba9d061cfe847d2472205b2352f875c6bf7c9358d4cdd2cc1f149288c6R37 - can we remove the check for systemd mounts?

I have tested this with very few actual remediations - we need to have a way, in our testing, to configure the system beforehand needing all of the remediations. I have run tests on el8 and el9 with all remediations enabled and verified that they are run correctly, or are correctly skipped.

@richm richm force-pushed the refactor-remediations branch from ba692dc to 42d1308 Compare November 26, 2025 20:54
@richm
Copy link
Collaborator Author

richm commented Nov 26, 2025

[citest]

@Monnte
Copy link
Contributor

Monnte commented Nov 27, 2025

@richm Hello, I am no longer working at RedHat and not maintaining this stuff, so I can't help you with that answer.

@amott-rh
Copy link
Contributor

@richm Probably in general RHEL 6 has become less relevant, but I wrote that remediation precisely because I had customer engagements that were upgrading RHEL 6 servers and ran into the /usr issue. I also have colleagues in the same position, but agree it's generally rare.

block:
- name: leapp_cgroups-v1_enabled | Show the remediation command
ansible.builtin.debug:
msg: "{{ leapp_inhibitor_remediation.context | join(' ') }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg: "{{ leapp_inhibitor_remediation.context | join(' ') }}"
bar: leapp_inhibitor_remediation.context | join(' ')

loop:
- "@^graphical-server-environment"
- gnome-desktop3
when: kde_install.stdout | length > 0 and gnome_install.stdout | length == 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the role can run package_facts, and then read if packages are installed from the facts returned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. I don't know if the package names kde-workspace and gnome-desktop3 are aliases - the rpm command can resolve aliases, but package_facts does not list the aliases as separate keys. I would rather leave this as-is.


# The old version passed the list directly to the command. I didn't think
# this was possible. Guard against something weird here. Assume non-string
# is a list.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeterMocary do you know where leapp inhibitors are stored? Maybe there is some KCS about this inhibitor that can provide us more info

@richm richm force-pushed the refactor-remediations branch from 6a9dbf1 to 40aa225 Compare December 1, 2025 15:17
@richm
Copy link
Collaborator Author

richm commented Dec 1, 2025

[citest]

@richm
Copy link
Collaborator Author

richm commented Dec 1, 2025

@spetrosi are these 7to8 and 9to10 errors expected?

@richm richm force-pushed the refactor-remediations branch from 6c050bf to 112f715 Compare December 2, 2025 15:54
…- do not use fail/rescue

There was a lot of code duplication in the remedation task files.  This has been extracted
into the remediation role main task file.

The remediation tasks were using fail/rescue for flow control, which makes looking at the
logs very confusing, as you really have to know which tasks to exclude when looking for errors.
Instead, use plain old conditionals with blocks for tasks to run conditionally.  NOTE: The
old way of using `rescue` would essentially catch and ignore all errors - this seems
wrong to me, but perhaps there is a reason.  This means that now, remediation may raise
errors where before it would not.

Use ansible good practices:

* Use `vars` instead of `set_fact` and keep the variables set at the lowest necessary scope
* Use filters instead of loops
* Use conditional evaluation instead of comparing a value `== true`
* Use tests such as `is success` rather than looking at the register rc value directly

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm force-pushed the refactor-remediations branch from 112f715 to c0fea5a Compare December 2, 2025 15:54
@richm
Copy link
Collaborator Author

richm commented Dec 2, 2025

[citest]

@richm
Copy link
Collaborator Author

richm commented Dec 2, 2025

Any objection to merging this? We will be adding tests for remediations in upcoming PRs

@richm richm merged commit aad9bfd into redhat-cop:main Dec 2, 2025
23 of 25 checks passed
@richm richm deleted the refactor-remediations branch December 2, 2025 21:18
@richm
Copy link
Collaborator Author

richm commented Dec 9, 2025

@richm Probably in general RHEL 6 has become less relevant, but I wrote that remediation precisely because I had customer engagements that were upgrading RHEL 6 servers and ran into the /usr issue. I also have colleagues in the same position, but agree it's generally rare.

@amott-rh What was the control node platform you used, and what was the version of ansible you used? Note that I don't believe any supported version of Ansible can manage a rhel6 system (python 2.6 is too old).

@amott-rh
Copy link
Contributor

@richm It was a while ago, but I probably used a RHEL 7 machine running Ansible 2.9. I was working with a customer who needs to migrate a good number of RHEL 6 machines to RHEL 7, then 8 then 9, and these playbooks were the most reliable and reproducible way to achieve this. As I understand it, this project is still in progress, but I absolutely understand your point - there comes a time when old version can't be reasonably supported by them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants