Creating a Netscaler VIP using ansible

Creating a content-switched VIP on a Netscaler is pretty easy but you need to complete the steps of creating the server, services, lb vserver, cs vserver.
If you need to create more than 1 VIP it will take some time to do this manually and it could also be error-prone.

Automation is your friend in this situation and in this project I used ansible. This project/script was written to create content-switched VIP, but it can also create an lb vserver VIP if you don’t use content-switching. It can also be used to remove it. It can also be used to add/remove a server to a VIP that was already created. You can do this using a combination of module tags and the state of each part of the VIP.

Usage:

In the vars file (group_vars/localVPX/vars) you have to define your tla name and the IP of the VIP, the service type of the VIP and the port, and the server IPs.
When you run it you also need to specify the state(present/absent) of each part of the VIP. Using absent you can remove any part of the vip. You can also remove the whole VIP if you want.
The process of creating a VIP needs 2 steps. So you need the run the script twice. This is because in the first step using a jinja template an SVG file is created and used in step2 for binding the services to the lb vserver.
So step 1 creates everything, but it can not bind the services to the lb vserver. Step2 it binds the services to the lb vserver.
You can also remove the VIP. This is also a 2-step process as you need to remove the cs vserver first (step1) and then you can remove all the other parts.

Examples:

you create a whole vip like this:

Step1 : ansible-playbook -i inventory create_cs.yml -e "server_state=present service_state=present lb_state=present cs_state=present" --skip-tags bindservices
Step2 : ansible-playbook -i inventory create_cs.yml -e "server_state=present service_state=present lb_state=present cs_state=present" --tags bindservices

you can also remove the VIP like this:

Step1 : ansible-playbook -i inventory create_cs.yml -e "server_state=present service_state=present lb_state=present cs_state=absent" --skip-tags bindservices
Step2 : ansible-playbook -i inventory create_cs.yml -e "server_state=absent service_state=absent lb_state=absent cs_state=absent" --skip-tags bindservices

Here you can find the files for this project:
https://github.com/czirakim/create-netscaler-vip


About the author

Mihai is a Senior Network Engineer with more than 15 years of experience

Leave a Reply

Your email address will not be published. Required fields are marked *