netscaler / ansible-collection-netscaleradc

Custom Ansible modules for NetScaler ADC and NetScaler ADM. Part of NetScaler Automation Toolkit | https://github.com/netscaler/automation-toolkit
https://netscaler.github.io/ansible-collection-netscaleradc/
MIT License
113 stars 57 forks source link

[FEATURE REQUEST]: Support for GET, GET (All) and GET filtered operations on resources #372

Open gusmb opened 8 months ago

gusmb commented 8 months ago

Summary

In current automation workflows it is common to run some pre-checks based on intended list of Nitro resources to configure, in order to exit an automation workflow early rather than running it all the way. For instance, checking if a Vserver is already configured, or retrieving the operational status of a vserver to report back to the user whether it is up or down based on provided configuration.

We currently do this using the citrix.adc by running nitro_request queries for "show" commands:

As an idea, would be nice to extend the current modules to provide the ability to retrieve the operational status of the resources instead of just looking at config. This could be supported by additional state flags "shown" and "shown_filtered"

Issue Type

Feature Idea

Component Name

ALL

Describe alternatives you've considered

Looking at observability exporter and telemetry data to check on existing objects.

Additional Information

gusmb commented 7 months ago

@sumanth-lingappa related to this issue, a probably more appropiate option to implement the GET, GET-ALL and filter operations would be through a lookup plugin:

This is an example use case:

{# Configure backup vserver address #}
{%     if vserver_item.failover_virtual_ip is defined %}
{%         do vserver_data.attributes.update({'backupvserver': vserver_item.failover_virtual_ip}) %}
{%     endif %}

In my abstracted data, I have the option to input an IP address corresponding to a VIP to be used as failover Vserver. As part of the config generation, I would need to lookup the Vserver name based on the VIP address value, since NITRO expects a Vserver string value for “backupvserver” instead of an IP address.

So ideally I would refactor the above Jinja snippet into the following:

{# Configure backup vserver address #}
{%     if vserver_item.failover_virtual_ip is defined %}
{%         do vserver_data.attributes.update({'backupvserver': query('netscaler.adc.resource_lookup',
                                                                       filter='ipv46=' ~ vserver_item.failover_virtual_ip,
                                                                       resource_type='lbvserver',
                                                                       match_mode='all' ) | first | map(attribute='name')}) %}
{%     endif %}

This lookup plugin “netscaler.adc.resource_lookup” would be a wrapper for the NITRO Get (one), Get (all) or “filter” search, where the filter params are provided as a string of comma separated key value pairs, and the resource_type indicates the api endpoint to query for the filter search.

Note the “match_mode” parameter for the filter search, which could have possible values “any” or “all”, to match on any of the provided filter params, or to match on all of them. Currently NITRO only supports a match on any approach, however, match on all is very useful and could be easily implemented in Python by doing extra filtering on the returned resources.

This would be super useful. The Terraform equivalent would be a data source resource that could be queried to get live config data to process.

sumanth-lingappa commented 5 months ago

Similar request as in #296 ? 🤔

gusmb commented 5 months ago

Similar request as in #296 ? 🤔

Similar, however lookup plugins fit better IMO, since they're callable from Ninja and you might need to query for data while rendering a template

sumanth-lingappa commented 5 months ago

Ok. good point. I am exploring this request. Are you aware of any other collection implementation of the lookup plugin? That will be helpful.

sumanth-lingappa commented 5 months ago

I guess I found many lookup plugin implementations at https://docs.ansible.com/ansible/latest/collections/index_lookup.html

gusmb commented 5 months ago

I guess I found many lookup plugin implementations at https://docs.ansible.com/ansible/latest/collections/index_lookup.html

Netbox has a good lookup query plugin:

https://docs.ansible.com/ansible/latest/collections/netbox/netbox/nb_lookup_lookup.html