infra.leapp icon indicating copy to clipboard operation
infra.leapp copied to clipboard

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

Open richm opened this issue 1 month ago • 4 comments

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 [email protected]

richm avatar Nov 26 '25 20:11 richm

@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 avatar Nov 26 '25 20:11 richm

[citest]

richm avatar Nov 26 '25 21:11 richm

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

Monnte avatar Nov 27 '25 08:11 Monnte

@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 avatar Nov 27 '25 10:11 amott-rh

[citest]

richm avatar Dec 01 '25 15:12 richm

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

richm avatar Dec 01 '25 18:12 richm

[citest]

richm avatar Dec 02 '25 16:12 richm

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

richm avatar Dec 02 '25 20:12 richm