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

Add remediate role to collection #150

Merged
merged 5 commits into from
Apr 10, 2024

Conversation

Monnte
Copy link
Contributor

@Monnte Monnte commented Jan 17, 2024

OAMG-10379

Introducing new role that is used to remediate the inhibitors related to the Leapp upgrade process.

@Monnte
Copy link
Contributor Author

Monnte commented Jan 17, 2024

TODO: I need to test if everything is working as expected.

@swapdisk swapdisk added the enhancement New feature or request label Jan 17, 2024
Copy link
Collaborator

@djdanielsson djdanielsson left a comment

Choose a reason for hiding this comment

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

Please fix all the lint errors

@Monnte
Copy link
Contributor Author

Monnte commented Jan 19, 2024

@djdanielsson Hello, I am working on fixing lint errors, but, the remediation playbooks are taken from insights and plan is automatically sync them into this role, but the lint fails on those playbooks. So my question is, can we ignore those files or the other (not preferred) option is to update all remediation playbooks to pass the lint. WDYT?

@djdanielsson
Copy link
Collaborator

No, the lint is required. Please reach out to me offline and we can discuss this a bit more in detail

@Monnte Monnte force-pushed the remediation-role branch 2 times, most recently from 3447392 to 3516437 Compare February 7, 2024 14:13
@Monnte
Copy link
Contributor Author

Monnte commented Feb 7, 2024

@djdanielsson Hi, can you try to rerun the linter now ?

@Monnte Monnte force-pushed the remediation-role branch 2 times, most recently from 6beea94 to 5705fb2 Compare February 13, 2024 13:34
@Monnte Monnte force-pushed the remediation-role branch 2 times, most recently from cd51498 to 5546135 Compare February 28, 2024 15:23
@Monnte
Copy link
Contributor Author

Monnte commented Feb 28, 2024

Pipeline now should pass, however there are some "nasty" things that should be fixed but didn't find time yet.

There were a lot of changes to the playbooks, some visual and some functional therefore we need to test them all again.

@Monnte Monnte marked this pull request as ready for review February 28, 2024 15:32
@Monnte Monnte requested review from djdanielsson and swapdisk March 6, 2024 09:00
@djdanielsson
Copy link
Collaborator

I have not really had time to look over the code, but if it passes lint and has been tested functionality I think I am willing to merge it @swapdisk thoughts?

@Monnte
Copy link
Contributor Author

Monnte commented Mar 7, 2024

I need to test those changes and merge it to the upstream in internal project, but when it's ready I'll let you know. So please wait with merging the branch. Thanks.

@swapdisk
Copy link
Member

swapdisk commented Mar 7, 2024

I need to test those changes and merge it to the upstream in internal project, but when it's ready I'll let you know. So please wait with merging the branch. Thanks.

Right, let's move the PR to draft in the meantime.

I have not really had time to look over the code, but if it passes lint and has been tested functionality I think I am willing to merge it @swapdisk thoughts?

I will give all this a good look through tomorrow.

@swapdisk swapdisk marked this pull request as draft March 7, 2024 23:01
@jeffmcutter
Copy link
Collaborator

I'm surprised uppercase file names pass lint. Is there a reason for them? The rest of the collection uses task files lower-lower-lower.yml, not UPPER_UPPER_UPPER.yml.

@Denney-tech
Copy link
Contributor

Denney-tech commented Mar 22, 2024

I'm surprised uppercase file names pass lint. Is there a reason for them? The rest of the collection uses task files lower-lower-lower.yml, not UPPER_UPPER_UPPER.yml.

While that's true, as a consumer I don't look at any of the other roles and think I need to do something like:

- include_role:
    name: infra.leapp.analysis
    tasks_from: analysis-leapp.yml

I would just use the default main.yml and let the role decide what task files to run, when and where.

In this case for this role, the default tasks_from: main.yml would do absolutely nothing unless I fill the remediation_todo: [] var with an array of task files I want it to run (filenames minus the extension). With this behavior in mind, and having to provide documentation about what these do, I think UPPER_UPPER_UPPER.yml is acceptable for all task files that might be called this way. Any other task files not called this way could use the usual lower-lower-lower.yml. This would also make it easier to sanitize the remediation_todo: [] var in an assertion step or by piping it to the upper filter during the loop.

In the meantime, the following playbook would never end since the main.yml file doesn't prevent itself from calling itself or other lower-cased task files.

- include_role:
    name: infra.leapp.remediation
  vars:
    remediation_playbooks:
      - LEAPP_NFS_DETECTED
      - main
    remediation_todo:
      - LEAPP_NFS_DETECTED
      - main

@Monnte Monnte force-pushed the remediation-role branch from 5546135 to f44b90f Compare March 26, 2024 12:19
@Monnte Monnte marked this pull request as ready for review March 26, 2024 12:20
@Monnte
Copy link
Contributor Author

Monnte commented Mar 26, 2024

I think, it is ready to be merged if there are no further requirements or changes.

Followup automatization for automatic update from the upstream is ready. Whenever the change is presented in upstream, our bot will create the PR to this repo, to update the playbook.

@jeffmcutter
Copy link
Collaborator

jeffmcutter commented Mar 26, 2024

@Denney-tech and @Monnte

Regarding the case. Users will have to keep track of uppercase vs. lowercase variable names.

I don't think I've ever seen another certified, validated, or well known community collection using uppercase variables and files.

As someone who has contributed a lot to this collection, I would really like to see the variable and file names remain consistent.

If it's too much of an ask, I can help rename them.

Thanks,
-Jeff

@djdanielsson
Copy link
Collaborator

djdanielsson commented Mar 26, 2024

I think something like this should do the trick for the variables that are all caps:

for i in $(find . -type f -name "*.yml");do sed -i 's/[A-Z(_)?]*\:/\L&/' "$i";done

and for the file names I think this should work but untested:

for i in $(find . -type f -name ".yml");do mv -v "$i" "`echo $i | tr '[A-Z]' '[a-z]'`";done

@Monnte
Copy link
Contributor Author

Monnte commented Mar 27, 2024

One more thing, those playbooks are for RHEL 8 remediation only I think, where would be the ideal place to mention this in documentation ?

Copy link
Collaborator

@djdanielsson djdanielsson left a comment

Choose a reason for hiding this comment

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

few small tweaks. I would put it at the top of the readme in the role itself and note it in the main readme as well where you added the line.

@Monnte
Copy link
Contributor Author

Monnte commented Mar 28, 2024

@djdanielsson thanks, for now I will adjust all the things to mention RHEL 8, until remediation for other version will be available.

Copy link
Collaborator

@djdanielsson djdanielsson left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@swapdisk swapdisk left a comment

Choose a reason for hiding this comment

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

After fixing the loop var, I was able to get further. I ran the role with using this just for testing:

remediation_todo:
  - leapp_missing_pkg

The role failed at the "Install the missing package via remediation command" task like this:

TASK [infra.leapp.remediate : leapp_missing_pkg | Install the missing package via remediation command] ***
fatal: [more-calf]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'str object' has no attribute 'context'. 'str object' has no attribute 'context'\\n\\nThe error appears to be in '/runner/requirements_collections/ansible_collections/infra/leapp/roles/remediate/tasks/leapp_missing_pkg.yml': line 31, column 7, but may\\nbe elsewhere in the file depending on the exact syntax problem.\\n\\nThe offending line appears to be:\\n\\n\\n    - name: leapp_missing_pkg | Install the missing package via remediation command\\n      ^ here\\n"}

It appears the remediation playbook expects to always find its corresponding inhibitors title in the leapp report file.

In the name of idempotency, may I suggest we make it so that remediation playbooks just gracefully do nothing if the corresponding inhibitor was not reported?

Copy link
Member

@swapdisk swapdisk left a comment

Choose a reason for hiding this comment

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

Bad sed! 😄

@Monnte Monnte requested a review from swapdisk April 2, 2024 10:25
@Monnte Monnte force-pushed the remediation-role branch 2 times, most recently from 08b8432 to 08fb997 Compare April 2, 2024 10:30
@Monnte Monnte force-pushed the remediation-role branch 2 times, most recently from 069dd50 to 6417d4d Compare April 2, 2024 14:35
@Monnte Monnte requested a review from swapdisk April 5, 2024 09:30
@Monnte Monnte force-pushed the remediation-role branch from 6417d4d to b816c3d Compare April 5, 2024 09:31
Copy link
Member

@swapdisk swapdisk left a comment

Choose a reason for hiding this comment

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

LGTM, but please add a change description under changelogs/fragments/.

@djdanielsson
Copy link
Collaborator

should we consider this a major change?

@swapdisk
Copy link
Member

swapdisk commented Apr 5, 2024

should we consider this a major change?

I think yes.

Copy link
Member

@swapdisk swapdisk left a comment

Choose a reason for hiding this comment

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

LGTM.

@djdanielsson djdanielsson merged commit 8f0bcfc into redhat-cop:main Apr 10, 2024
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants