Exercise 2.1: Using a combination of modules to delete configuration on the BIG-IP

Objective

Demonstrate use of the different modules to delete the configuration (Nodes/Pool/Virtual Server) on the BIG-IP. # Guide

Step 1

Using your text editor of choice create a new file called bigip-delete-configuration.yml.

[student1@ansible ~]$ nano bigip-delete-configuration.yml

``vim`` and ``nano`` are available on the control node

Step 2

Enter the following play definition into bigip-delete-configuration.yml:

---
- name: BIG-IP SETUP
  hosts: lb
  connection: local
  gather_facts: false

      vars_files:
    virtuals_pools.yml
  • The --- at the top of the file indicates that this is

a YAML file. - The hosts: f5, indicates the play is run only on the F5 BIG-IP device - connection: local tells the Playbook to run locally (rather than SSHing to itself) - gather_facts: no disables facts gathering. We are not using any fact variables for this playbook.

Step 3

Add a tasks section with a set_fact for setting the provider values

tasks:
- name: Setup provider
  set_fact:
    provider:
     server: "{{private_ip}}"
     user: "{{ansible_user}}"
     password: "{{ansible_ssh_pass}}"
     server_port: "8443"
     validate_certs: "no"

Step 4

Next, add the first task using the bigip_virtual_server. This task will be identical to Exercise 1.5 - Adding a virtual server with an additional state parameter. The state: absent will remove the configuration from the F5 BIG-IP load balancer.

- name: DELETE VIRTUAL SERVER
  bigip_virtual_server:
   provider: "{{provider}}"
   name: "{{item.vs_name}}"
   state: absent
  loop: "{{vips_pools}}"
  • state: absent is a parameter that tells the module to delete the configuration

Step 5

Next, add the second task using the bigip_pool. This task will be identical to Exercise 1.3 - Adding a load balancing pool with an additional state parameter set to absent.

- name: DELETE POOL
  bigip_pool:
   provider: "{{provider}}"
   name: "{{item.pool_name}}"
   state: absent
  loop: "{{vips_pools}}"

Step 6

Finally, add the last task using the bigip_node. This task will be identical to Exercise 1.2 - Adding nodes to F5 BIG-IP with an additional state parameter set to``absent``.

- name: DELETE NODES
  bigip_node:
   provider: "{{provider}}"
   name: "{{hostvars[item].inventory_hostname}}"
   state: absent
 loop: "{{ groups['webservers'] }}"

The above playbook will delete the virtual server, then the pool and then the nodes configured in previous exercises. Please note the order of the playbooks and that this is mandatory to have the configuration removed in the right order.

Step 7

Run the playbook - exit back into the command line of the control host and execute the following:

[student1@ansible ~]$ ansible-playbook bigip-delete-configuration.yml

Playbook Output

PLAY [BIG-IP TEARDOWN] **************************************************************************************************************************************

TASK [Setup provider] ***************************************************************************************************************************************
ok: [f5]

TASK [DELETE VIRTUAL SERVER] ********************************************************************************************************************************
changed: [f5] => (item={u'pool_name': u'http-pool', u'vs_name': u'vip', u'port': 8081})
changed: [f5] => (item={u'pool_name': u'http-pool1', u'vs_name': u'vip1', u'port': 8082})
changed: [f5] => (item={u'pool_name': u'http-pool2', u'vs_name': u'vip2', u'port': 8083})
changed: [f5] => (item={u'pool_name': u'http-pool3', u'vs_name': u'vip3', u'port': 8084})
changed: [f5] => (item={u'pool_name': u'http-pool4', u'vs_name': u'vip4', u'port': 8085})
changed: [f5] => (item={u'pool_name': u'http-pool5', u'vs_name': u'vip5', u'port': 8086})
changed: [f5] => (item={u'pool_name': u'http-pool6', u'vs_name': u'vip6', u'port': 8087})
changed: [f5] => (item={u'pool_name': u'http-pool7', u'vs_name': u'vip7', u'port': 8088})
changed: [f5] => (item={u'pool_name': u'http-pool8', u'vs_name': u'vip8', u'port': 8089})
changed: [f5] => (item={u'pool_name': u'http-pool9', u'vs_name': u'vip9', u'port': 8090})
changed: [f5] => (item={u'pool_name': u'http-pool10', u'vs_name': u'vip10', u'port': 8091})
changed: [f5] => (item={u'pool_name': u'http-pool11', u'vs_name': u'vip11', u'port': 8092})
changed: [f5] => (item={u'pool_name': u'http-pool12', u'vs_name': u'vip12', u'port': 8093})
changed: [f5] => (item={u'pool_name': u'http-pool13', u'vs_name': u'vip13', u'port': 8094})
changed: [f5] => (item={u'pool_name': u'http-pool14', u'vs_name': u'vip14', u'port': 8095})
changed: [f5] => (item={u'pool_name': u'http-pool15', u'vs_name': u'vip15', u'port': 8096})

TASK [DELETE POOL] ******************************************************************************************************************************************
changed: [f5] => (item={u'pool_name': u'http-pool', u'vs_name': u'vip', u'port': 8081})
changed: [f5] => (item={u'pool_name': u'http-pool1', u'vs_name': u'vip1', u'port': 8082})
changed: [f5] => (item={u'pool_name': u'http-pool2', u'vs_name': u'vip2', u'port': 8083})
changed: [f5] => (item={u'pool_name': u'http-pool3', u'vs_name': u'vip3', u'port': 8084})
changed: [f5] => (item={u'pool_name': u'http-pool4', u'vs_name': u'vip4', u'port': 8085})
changed: [f5] => (item={u'pool_name': u'http-pool5', u'vs_name': u'vip5', u'port': 8086})
changed: [f5] => (item={u'pool_name': u'http-pool6', u'vs_name': u'vip6', u'port': 8087})
changed: [f5] => (item={u'pool_name': u'http-pool7', u'vs_name': u'vip7', u'port': 8088})
changed: [f5] => (item={u'pool_name': u'http-pool8', u'vs_name': u'vip8', u'port': 8089})
changed: [f5] => (item={u'pool_name': u'http-pool9', u'vs_name': u'vip9', u'port': 8090})
changed: [f5] => (item={u'pool_name': u'http-pool10', u'vs_name': u'vip10', u'port': 8091})
changed: [f5] => (item={u'pool_name': u'http-pool11', u'vs_name': u'vip11', u'port': 8092})
changed: [f5] => (item={u'pool_name': u'http-pool12', u'vs_name': u'vip12', u'port': 8093})
changed: [f5] => (item={u'pool_name': u'http-pool13', u'vs_name': u'vip13', u'port': 8094})
changed: [f5] => (item={u'pool_name': u'http-pool14', u'vs_name': u'vip14', u'port': 8095})
changed: [f5] => (item={u'pool_name': u'http-pool15', u'vs_name': u'vip15', u'port': 8096})

TASK [DELETE NODES] *****************************************************************************************************************************************
changed: [f5] => (item=host1)
changed: [f5] => (item=host2)

Solution

The finished Ansible Playbook is provided here for an Answer key. Click here: bigip-delete-configuration.yml.

Verifying the Solution

Login to the F5 with your web browser to see what was configured. Grab the IP information for the F5 load balancer from the lab_inventory/hosts file, and type it in like so: https://X.X.X.X:8443/

Login information for the BIG-IP: - username: admin - password: admin

Navigate the menu on the left and view that the configuration has been deleted.

  • Local Traffic Manager -> Virtual Server
  • Local Traffic Manager -> Pool
  • Local Traffic Manager -> Node

You have finished this exercise.