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

Added a switch to toggle the sort function in the OGs Module #189

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/module_utils/network/asa/argspec/ogs/ogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class OGsArgs(object):
},
},
"running_config": {"type": "str"},
"sortgroups": {"type": "bool", "default" : True},
"state": {
"choices": [
"merged",
Expand Down
10 changes: 6 additions & 4 deletions plugins/module_utils/network/asa/facts/ogs/ogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
9 changes: 8 additions & 1 deletion plugins/modules/asa_ogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down