Skip to content

Conversation

@jan-cerny
Copy link
Collaborator

@jan-cerny jan-cerny commented Jul 23, 2025

Description:

This PR introduces additional logic to builder that builds profile oriented Ansible Playbooks. The goal is to reduce amount of ansible.builtin.package_facts and ansible.builtin.service_facts in the built Ansible Playbook.

The builder changes order of Ansible Tasks in the Ansible Playbook.

It moves all Ansible Tasks that install or remove packages to the beginning of the Playbook. The outcome of moving these Ansible Tasks is that just two instances of ansible.builtin.package_facts Ansible Tasks are needed in the Ansible Playbook - first at the beginning of the Ansible Playbook and second after the package installation or removal part.

Similarly, tasks that enable or disable systemd services are moved to beginning, right after installing packages, to prevent need for having multiple ansible.builtin.service_facts in the Ansible Playbook.

We can't merge the package installation or removal Ansible Tasks to only 2 Ansible Tasks (one for installation and one for removal) because that would break the use case of skipping or selecting specific rules by using tags.

Rationale:

Our Ansible Playbooks take a long time to run. This change will decrease the time they need to complete. Experiments suggest that the change brings about 15 % speed up of a CIS playbook.

Resolves: https://issues.redhat.com/browse/OPENSCAP-6045

Review Hints:

Contest tests /hardening/ansible

@jan-cerny jan-cerny added this to the 0.1.78 milestone Jul 23, 2025
@jan-cerny jan-cerny added the Ansible Ansible remediation update. label Jul 23, 2025
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Jul 23, 2025
@openshift-ci
Copy link

openshift-ci bot commented Jul 23, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Set package name at build time instead of run time.  This change
prevents dependency between a `set_fact` task and a `package` task which
complicates the logic of the playbook.
These tasks register a variable but that variable isn't used anywhere.
Instead of gathering service_facts each time when it's needed we
will do it at the beginning of the Playbook but after installing
all packages.
The goal of this change is to enable and disable all systemd services at
the beginning of the Ansible Playbook, after all packages are installed
and uninstalled, before `service_facts` are gathered.

To make the processing in the Ansible Playbook builder easier for us we
will slightly change the templates `service_enabled` and
`service_disabled`. We will wrap all tasks in these templates to a block
and we will mark this block by a special tag.  We will us this special
tag to easily identify this block in the Ansible Playbook builder
script.
@jan-cerny jan-cerny changed the title Reduce gathering package facts in profile Ansible Playbooks Reduce gathering facts in profile Ansible Playbooks Jul 25, 2025
@jan-cerny jan-cerny marked this pull request as ready for review July 25, 2025 10:18
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Jul 25, 2025
@Mab879 Mab879 self-assigned this Jul 25, 2025
@Mab879 Mab879 merged commit 6f8d88a into ComplianceAsCode:master Jul 28, 2025
123 of 129 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ansible Ansible remediation update.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants