- Order in sections list view
+ Name of the section
.. raw:: html
@@ -237,21 +237,21 @@ Parameters
* - .. raw:: html
-
+
- .. _ansible_collections.codeaffen.phpipam.section_module__parameter-name:
+ .. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_by:
.. rst-class:: ansible-option-title
- **name**
+ **order_by**
.. raw:: html
-
+
.. ansible-option-type-line::
- :ansible-option-type:`string` / :ansible-option-required:`required`
+ :ansible-option-type:`string`
.. raw:: html
@@ -261,7 +261,61 @@ Parameters
- Name of the section
+ Specifies the field to use for sorting the returned subnets
+
+
+ .. rst-class:: ansible-option-line
+
+ :ansible-option-choices:`Choices:`
+
+ - :ansible-option-choices-entry:`"subnet"`
+ - :ansible-option-choices-entry:`"description"`
+
+
+ .. raw:: html
+
+
+
+ * - .. raw:: html
+
+
+
+
+ .. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_direction:
+
+ .. rst-class:: ansible-option-title
+
+ **order_direction**
+
+ .. raw:: html
+
+
+
+ .. ansible-option-type-line::
+
+ :ansible-option-type:`string`
+
+ .. raw:: html
+
+
+
+ - .. raw:: html
+
+
+
+ Determines the sorting direction, either ascending or descending
+
+ 'asc' sorts from A to Z or from smallest to largest number
+
+ 'desc' sorts from Z to A or from largest to smallest number
+
+
+ .. rst-class:: ansible-option-line
+
+ :ansible-option-choices:`Choices:`
+
+ - :ansible-option-choices-entry:`"asc"`
+ - :ansible-option-choices-entry:`"desc"`
.. raw:: html
@@ -624,44 +678,6 @@ Parameters
- :ansible-option-choices-entry:`true`
- .. raw:: html
-
-
-
- * - .. raw:: html
-
-
-
-
- .. _ansible_collections.codeaffen.phpipam.section_module__parameter-subnet_ordering:
-
- .. rst-class:: ansible-option-title
-
- **subnet_ordering**
-
- .. raw:: html
-
-
-
- .. ansible-option-type-line::
-
- :ansible-option-type:`string`
-
- .. raw:: html
-
-
-
- - .. raw:: html
-
-
-
- How to order subnets within this section
-
-
- .. rst-class:: ansible-option-line
-
- :ansible-option-default-bold:`Default:` :ansible-option-default:`"subnet,asc"`
-
.. raw:: html
diff --git a/plugins/modules/section.py b/plugins/modules/section.py
index 954c665..4e34c1f 100644
--- a/plugins/modules/section.py
+++ b/plugins/modules/section.py
@@ -56,14 +56,18 @@
type: bool
required: false
default: no
- subnet_ordering:
- description: How to order subnets within this section
+ order_by:
+ description: Specifies the field to use for sorting the returned subnets
type: str
+ choices: [ subnet, description ]
required: false
- default: "subnet,asc"
- list_order:
- description: Order in sections list view
- type: int
+ order_direction:
+ description:
+ - Determines the sorting direction, either ascending or descending
+ - "'asc' sorts from A to Z or from smallest to largest number"
+ - "'desc' sorts from Z to A or from largest to smallest number"
+ type: str
+ choices: [ asc, desc ]
required: false
show_vlan:
description: Show/hide VLANs in subnet list view
@@ -125,17 +129,26 @@ def main():
parent=dict(type='entity', controller='sections', required=False, default=None, phpipam_name='masterSection'),
permissions=dict(type='json', required=False, default=None),
strict_mode=dict(type='bool', required=False),
- subnet_ordering=dict(type='bool', required=False, phpipam_name='subnetOrdering'),
- list_order=dict(type='bool', required=False, phpipam_name='order'),
+ order_by=dict(type=str, required=False, choices=['subnet', 'description']),
+ order_direction=dict(type=str, required=False, choices=['asc', 'desc']),
+ subnetOrdering=dict(type=str, required=False),
show_vlan=dict(type='bool', required=False, phpipam_name='showVLAN'),
show_vrf=dict(type='bool', required=False, phpipam_name='showVRF'),
show_supernets_only=dict(type='bool', required=False, phpipam_name='showSupernetOnly'),
dns_resolver=dict(type='entity', controller='tools/nameservers', required=False, phpipam_name='DNS'),
- )
+ ),
+ required_together=[['order_by', 'order_direction']],
)
- if not module.desired_absent:
- pass
+ module_params = module.phpipam_params
+
+ if 'order_by' in module_params and 'order_direction' in module_params:
+ module_params['subnetOrdering'] = module_params['order_by'] + ',' + module_params['order_direction']
+ del module_params['order_by']
+ del module_params['order_direction']
+
+ # if not module.desired_absent:
+ # pass
with module.api_connection():
module.run()
diff --git a/tests/test_playbooks/tasks/section.yml b/tests/test_playbooks/tasks/section.yml
index 36cde32..cf88b21 100644
--- a/tests/test_playbooks/tasks/section.yml
+++ b/tests/test_playbooks/tasks/section.yml
@@ -10,7 +10,8 @@
parent: "{{ section.parent | default(omit) }}"
permissions: "{{ section.permissions | default(omit) }}"
strict_mode: "{{ section.strict_mode | default(omit) }}"
- subnet_ordering: "{{ section.subnet_ordering | default(omit) }}"
+ order_by: "{{ section.order_by | default(omit) }}"
+ order_direction: "{{ section.order_direction | default(omit) }}"
list_order: "{{ section.list_order | default(omit) }}"
show_vlan: "{{ section.show_vlan | default(omit) }}"
show_vrf: "{{ section.show_vrf | default(omit) }}"
diff --git a/tests/test_playbooks/vars/section.yml b/tests/test_playbooks/vars/section.yml
index 5884d78..9e5329f 100644
--- a/tests/test_playbooks/vars/section.yml
+++ b/tests/test_playbooks/vars/section.yml
@@ -2,6 +2,8 @@
base_section_data:
name: "Example Inc."
show_supernets_only: yes
+ order_by: subnet
+ order_direction: asc
sections:
- name: "ACME Inc."