Skip to content

[Brownfield Network Settings] Granular Server Filtering for Network Management Details#442

Merged
madhansansel merged 9 commits intocisco-en-programmability:mainfrom
Kandarimegha:config_generator
Apr 29, 2026
Merged

[Brownfield Network Settings] Granular Server Filtering for Network Management Details#442
madhansansel merged 9 commits intocisco-en-programmability:mainfrom
Kandarimegha:config_generator

Conversation

@Kandarimegha
Copy link
Copy Markdown

@Kandarimegha Kandarimegha commented Apr 24, 2026

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Description

This PR enhances the network_settings_playbook_config_generator module by adding granular filtering capabilities for network_management_details. Previously, users could only filter by site_name_list, which resulted in all server types being included in the generated YAML output.

With this change, users can now selectively retrieve specific server configurations, improving flexibility and reducing unnecessary data in generated configs.

Key Enhancements
Added support for server_types filter to restrict output to specific server configurations (e.g., DNS, NTP, DHCP, AAA, etc.)
Added support for ip_address_list filter to include only sites containing specified IP addresses across server settings
Enabled combined filtering for more precise output control

Testing Done:

  • [] Manual testing
  • [] Unit tests
  • [] Integration tests

Test cases covered: [Mention test case IDs or brief points]

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • All the sanity checks have been completed and the sanity test cases have been executed

Ansible Best Practices

  • Tasks are idempotent (can be run multiple times without changing state)
  • Variables and secrets are handled securely (e.g., using ansible-vault or environment variables)
  • Playbooks are modular and reusable
  • Handlers are used for actions that need to run on change

Documentation

  • All options and parameters are documented clearly.
  • Examples are provided and tested.
  • Notes and limitations are clearly stated.

Screenshots (if applicable)

Notes to Reviewers

- snmp_server
- syslog_server
- timezone
- message_of_the_day
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add ip address list?

              ip_address_list:
                description:
                - List of server IP addresses to filter sites by.
                - A site is included only if B(any) of its server
                  settings contains B(any) of the specified IPs.
                - Uses exact match. Combined with C(site_name_list)
                  and C(server_types) using AND logic.
                - If omitted, no IP-based filtering is applied
                  (default/backward-compatible behaviour).
                type: list
                elements: str
                required: false

"timezone",
"message_of_the_day",
]
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema missing?


                        "ip_address_list": {
                            "type": "list",
                            "required": False,
                            "elements": "str"
                        },

# server IPs match any of the requested IPs (AND with other filters)
if requested_ip_addresses:
site_ips = self._collect_server_ips(filtered_settings)
matched = any(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for ip address.. do we need to match sub-string? or compare with exact string?

                    matched = any(
                        req_ip in site_ips
                        for req_ip in requested_ip_addresses
                    )

- snmp_server
- syslog_server
- timezone
- message_of_the_day
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IP address list examples?

# Network management details filtered by server IP address.
# Only sites whose server settings contain any of the listed IPs are included.
- name: Generate YAML Configuration for network management - filtered by IP
  cisco.dnac.network_settings_playbook_config_generator:
    dnac_host: "{{dnac_host}}"
    dnac_username: "{{dnac_username}}"
    dnac_password: "{{dnac_password}}"
    dnac_verify: "{{dnac_verify}}"
    dnac_port: "{{dnac_port}}"
    dnac_version: "{{dnac_version}}"
    dnac_debug: "{{dnac_debug}}"
    dnac_log: true
    dnac_log_level: "{{dnac_log_level}}"
    state: gathered
    file_path: "/tmp/network_mgmt_by_ip.yml"
    file_mode: "overwrite"
    config:
      component_specific_filters:
        components_list:
          - "network_management_details"
        network_management_details:
          - ip_address_list:
              - "10.1.1.10"
              - "8.8.8.8"

# Combined: site + server type + IP address filters (AND logic across all three).
- name: Generate YAML Configuration - combined site, server type, and IP filter
  cisco.dnac.network_settings_playbook_config_generator:
    dnac_host: "{{dnac_host}}"
    dnac_username: "{{dnac_username}}"
    dnac_password: "{{dnac_password}}"
    dnac_verify: "{{dnac_verify}}"
    dnac_port: "{{dnac_port}}"
    dnac_version: "{{dnac_version}}"
    dnac_debug: "{{dnac_debug}}"
    dnac_log: true
    dnac_log_level: "{{dnac_log_level}}"
    state: gathered
    file_path: "/tmp/network_mgmt_combined.yml"
    file_mode: "overwrite"
    config:
      component_specific_filters:
        components_list:
          - "network_management_details"
        network_management_details:
          - site_name_list:
              - "Global/USA/California"
            server_types:
              - dns_server
              - dhcp_server
            ip_address_list:
              - "10.1.1.10"

]
}
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test for IP address list??

@@ -129,10 +129,17 @@
required: false
network_management_details:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

          network_management_details:
            description:
            - Network management settings to filter by site,
              server type, and/or server IP address.
            - Each list entry is an independent filter dict.
              Within a single entry, all specified filters
              (C(site_name_list), C(server_types),
              C(ip_address_list)) are combined with B(AND)
              logic. Omitting a filter means no restriction
              on that attribute.
            - If C(network_management_details) sub-filter is
              not provided under
              C(component_specific_filters), the module
              defaults to retrieving settings for the
              B(Global) (root) site only.
            - To retrieve settings for specific sites,
              provide a C(site_name_list) with the desired
              site names.
            - To retrieve only specific server types, provide
              a C(server_types) list.
            - To include only sites whose server settings
              match a specific server IP, provide
              C(ip_address_list). A site is included only if
              B(any) of its server IPs matches B(any) of the
              specified addresses (OR across IPs, AND with
              site and server-type filters).
            - Evaluation order is site filtering first, then
              C(server_types) pruning, then
              C(ip_address_list) matching against the pruned
              settings.
            - If C(server_types) is omitted, all server types
              are retrieved (backward-compatible).
            - If C(ip_address_list) is omitted, no IP
              filtering is applied.

required: false
server_types:
description:
- List of server/settings types to include in the output.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

          server_types:
            description:
            - Restricts the YAML output to only the
              listed server-type keys. Server types not
              in this list are pruned from the generated
              settings dict for each site.
            - Combined with C(site_name_list) and
              C(ip_address_list) using AND logic.
              C(ip_address_list) matching runs after
              server-type pruning, so only IPs from
              the retained server types are evaluated.
            - If omitted, all server types are included
              in the output (backward-compatible).
            - "Example: C([dns_server, ntp_server])
              returns only DNS and NTP settings."
            type: list
            elements: str
            required: false
            choices:
              - dhcp_server
              - dns_server
              - ntp_server
              - network_aaa
              - client_and_endpoint_aaa
              - netflow_collector
              - snmp_server
              - syslog_server
              - timezone
              - message_of_the_day

@madhansansel madhansansel merged commit c3c1df8 into cisco-en-programmability:main Apr 29, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants