Ansible NITRO API calls

This repository contains sample playbooks that make NITRO API calls using standard Ansible modules.

Each playbook contains only one or two tasks. For more complete workflows tasks should be combined in a more complete playbook. Such examples can be found under the examples directory.

Playbook listing

In the following sections we detail the function of each playbook.

All playbooks require to be run with the delegate_to: localhost option since we do not want Ansible to connect to Netscaler directly but instead run the NITRO API calls from localhost addressed to the Netscaler NSIP.

There is a number of variables that each playbook uses. These are defined withing each playbook.

The exception is the NITRO API credentials variables which are defined in the inventory file. These variables ( {{ nsip }}, {{ nitro_user }}, {{ nitro_pass }} ) are needed in all playbooks.

Following are the details of each playbook.

Direct NetScaler API calls

These playbooks are under the ns/ directory.

ns_file_delete.yaml

Deletes a file on Netscaler.

Variables:

  • filelocation: path of the file on Netscaler
  • filename: name of the file on Netscaler

ns_file_get.yaml

Retrieve a file from Netscaler.

Variables:

  • filelocation: path of the file on Netscaler.
  • filename: name of the file on Netscaler.
  • localfile: absolute path of the target saved local file.

ns_file_put.yaml

Upload a file to Netscaler.

Variables:

  • filelocation: path of the file on Netscaler.
  • filename: name of the file on Netscaler.
  • localfile: absolute path of the source local file.

ns_reboot.yaml

Reboot Netscaler.

Note that this NITRO API call does not work with CPX. You will need to use docker commands to restart the CPX container.

Variables:

  • warm_reboot: boolean value to do a warm reboot.

ns_resource_add.yaml

Add a configuration resource to Netscaler.

Variables:

  • resource: path of the resource.
  • request_payload: request JSON content.

Refer to NITRO reference documentation for variable values explanation.

ns_resource_delete.yaml

Delete a configuration resource on Netscaler.

Variables:

  • resource: path of the resource.

Refer to NITRO reference documentation for variable values explanation.

ns_resource_enable_disable.yaml

Disable a configuration resource on Netscaler.

Variables:

  • resource: path of the resource.
  • request_payload: request JSON content.
  • resource_action: 'enable' / 'disable' the resource.

Refer to NITRO reference documentation for variable values explanation.

ns_resource_get.yaml

Get details of a single configuration resource.

Variables:

  • resource: path of the resource.

The returned data is under the json key in the playbook return value.

ns_resource_get_all.yaml

Get details of all resources of one kind.

Variables:

  • resource: path of the resource.

The returned data is under the json key in the playbook return value.

ns_resource_get_attrs.yaml

Get specific attributes of a configuration resource.

Variables:

  • resource: path of the resource.
  • attrs: list of attributes to retrieve.

The returned data is under the json key in the playbook return value.

ns_resource_update.yaml

Update the attributes of an existing resource.

  • resource: path of the resource.
  • request_payload: request JSON content.

ns_save_running_config.yaml

Save Netscaler's running configuration.

ns_feature

Enable / Disable Netscaler feature.

Variables:

  • feature_action: determine the action to be performed. Valid values are enable, disable.
  • request_payload: request JSON content.

NetScaler NITRO API calls through MAS

Under the playbooks/mas/ directory exist a number of playbooks that configure a NetScaler instace through a MAS access point.

In this case we have to login to MAS to get an authorization token which we use in the subsequent NITRO API calls.

To inform MAS that the NITRO API call is directed to a managed NetScaler instance and not to MAS directly we have to include either of these HTTP request headers.

  • _MPS_API_PROXY_MANAGED_INSTANCE_NAME: Name of the managed instance.
  • _MPS_API_PROXY_MANAGED_INSTANCE_IP: IP address of the managed instance.
  • _MPS_API_PROXY_MANAGED_INSTANCE_ID: ID of the managed instance.

In the playbooks we use _MPS_API_PROXY_MANAGED_INSTANCE_IP but any of the other headers are also suitable.

Note the nsip, nitro_user and nitro_pass variables must be set to match the MAS ip address and NITRO API credentials. Once we get the login token from MAS no other credentials are necessary. Namely there is no need to use any of the managed NetScaler instances login credentials.

There exist the follwoing playbooks:

  • mas_ns_resource_add.yaml
  • mas_ns_resource_delete.yaml
  • mas_ns_resource_disable.yaml
  • mas_ns_resource_enable.yaml
  • mas_ns_resource_get.yaml
  • mas_ns_resource_get_all.yaml
  • mas_ns_resource_get_attrs.yaml
  • mas_ns_resource_update.yaml
  • mas_ns_save_running_config.yaml
  • mas_ns_feature_enable_disable.yaml
  • mas_ns_file_delete.yaml
  • mas_ns_file_get.yaml
  • mas_ns_file_put.yaml
  • mas_ns_reboot.yaml

The variables used and operations results are the same as the similarly named NetScaler playbooks under playbooks/ns/.

Refer to the corresponding NetScaler playbook for each one's documentation.