Skip to content

Commit

Permalink
Fix Ansible Tasks order
Browse files Browse the repository at this point in the history
In #11033, we
have switched to a new script for generating profile oriented
Ansible Playbooks. Unfortunately, when Python 2 is used the
generated Ansible Playbooks don't preserve the order of Ansible
Tasks in the order defined in the SCAP source data stream.
The wrong order of Ansible Tasks in a Playbook might cause
an unexpected conflict between them during the run, for example
#11104.
The root cause of the problem is that dictionaries in Python 2
don't preserve order of elements but starting from Python 3.6
the dictionaries preserve order of its elements.

Fixes: #11104
  • Loading branch information
jan-cerny committed Sep 14, 2023
1 parent f0d2c92 commit b86685b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions build-scripts/generate_profile_remediations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python3

import argparse
import collections
import os
import re
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -192,7 +193,7 @@ def get_benchmark_data(self):
self.variables = get_all_variables(benchmark)

def load_all_remediations(self, benchmark):
self.remediations = {}
self.remediations = collections.OrderedDict()
rule_xpath = ".//{%s}Rule" % (XCCDF12_NS)
for rule_el in benchmark.findall(rule_xpath):
rule_id = rule_el.get("id")
Expand Down Expand Up @@ -238,7 +239,7 @@ def create_output_ansible(self, profile_el):
def collect_ansible_vars_and_tasks(self, profile_el):
selected_rules = get_selected_rules(profile_el)
refinements = get_value_refinenements(profile_el)
all_vars = {}
all_vars = collections.OrderedDict()
all_tasks = []
for rule_id, fix_el in self.remediations.items():
if rule_id not in selected_rules:
Expand Down

0 comments on commit b86685b

Please sign in to comment.