diff --git a/plugins/module_utils/network/asa/argspec/ogs/ogs.py b/plugins/module_utils/network/asa/argspec/ogs/ogs.py index 30420dc9..7a319690 100644 --- a/plugins/module_utils/network/asa/argspec/ogs/ogs.py +++ b/plugins/module_utils/network/asa/argspec/ogs/ogs.py @@ -244,6 +244,7 @@ class OGsArgs(object): }, }, "running_config": {"type": "str"}, + "sortgroups": {"type": "bool", "default" : True}, "state": { "choices": [ "merged", diff --git a/plugins/module_utils/network/asa/facts/ogs/ogs.py b/plugins/module_utils/network/asa/facts/ogs/ogs.py index 65cd7662..ab7e02eb 100644 --- a/plugins/module_utils/network/asa/facts/ogs/ogs.py +++ b/plugins/module_utils/network/asa/facts/ogs/ogs.py @@ -86,10 +86,12 @@ def populate_facts(self, connection, ansible_facts, data=None): obj_gp[object_groups.get(k)] = each[1] config_dict["object_groups"].append(obj_gp) obj_gp = {} - config_dict["object_groups"] = sorted( - config_dict["object_groups"], - key=lambda k, sk="name": str(k[sk]), - ) + sortgroups = self._module.params.get("sortgroups", True) + if sortgroups: + config_dict["object_groups"] = sorted( + config_dict["object_groups"], + key=lambda k, sk="name": str(k[sk]), + ) ogs.append(config_dict) # sort the object group list of dict by object_type ogs = sorted(ogs, key=lambda i: i["object_type"]) diff --git a/plugins/modules/asa_ogs.py b/plugins/modules/asa_ogs.py index 42a226af..5446f952 100644 --- a/plugins/modules/asa_ogs.py +++ b/plugins/modules/asa_ogs.py @@ -277,6 +277,13 @@ value of this option should be the output received from device by executing command. type: str + sortgroups: + description: + - The module, by default, will sort all outputted groups by alphabet. There are times + when it is not desirable to have the groups sorted. Example: You want to use the output + from state 'gathered' as input for the state 'replaced' (the groups have dependencies + to each other, so they have to be configured in the correct order). + type: boolean state: description: - The state the configuration should be left in @@ -1062,7 +1069,7 @@ def main(): ("state", "parsed", ("running_config",)), ] - mutually_exclusive = [("config", "running_config")] + mutually_exclusive = [("config", "running_config","sortgroups")] module = AnsibleModule( argument_spec=OGsArgs.argument_spec,