Example Playbook and Setup v1

Follow this tutorial to create a pool, add two members to that pool, and assign a virtual server to serve requests to the members in the pool.

You can create your own yaml file to use as a playbook, or follow along with this yaml file.

Creating an inventory file

All Ansible work starts with an inventory file.

For the purposes of this tutorial, it is not necessary to have anything special in the inventory file because we will be specifying our BIG-IP connection information within the playbook itself.

If you want to see more thorough examples of inventory in Ansible, we recommend you refer to inventory documentation found on Ansible’s website.

Let’s put the following text in a new file located at inventory/hosts.

localhost

The Playbook

Create a file called playbook.yaml in your current working directory and place the following content within it.

---
- name: Create a VIP, pool and pool members
  hosts: all
  connection: local

     vars:
       provider:
         password: admin
         server: 1.1.1.1
         user: admin
         validate_certs: no
         server_port: 443

   tasks:

     - name: Create a pool
       bigip_pool:
         provider: "{{ provider }}"
         lb_method: ratio-member
         name: web
         slow_ramp_time: 120
       delegate_to: localhost

     - name: Add members to pool
       bigip_pool_member:
         provider: "{{ provider }}"
         description: "webserver {{ item.name }}"
         host: "{{ item.host }}"
         name: "{{ item.name }}"
         pool: web
         port: 80
       with_items:
         - host: 10.10.10.10
           name: web01
         - host: 10.10.10.20
           name: web02
       delegate_to: localhost

     - name: Create a VIP
       bigip_virtual_server:
         provider: "{{ provider }}"
         description: foo-vip
         destination: 172.16.10.108
         name: vip-1
         pool: web
         port: 80
         snat: Automap
         profiles:
           - http
           - clientssl
       delegate_to: localhost

Run the playbook

We can now run our playbook. We will run this from the top-level ansible directory. Refer to the command below.

ansible-playbook -i inventory/hosts playbook.yaml

If you followed the above steps correctly, you should see output similar to what is shown below.

PLAY [Create a VIP, pool and pool members] ***********************************************

TASK [Gathering Facts] *******************************************************************
ok: [localhost]

TASK [Create a pool] *********************************************************************
changed: [localhost -> localhost]

TASK [Add members to pool] ***************************************************************
changed: [localhost -> localhost] => (item={u'host': u'10.10.10.10', u'name': u'web01'})
changed: [localhost -> localhost] => (item={u'host': u'10.10.10.20', u'name': u'web02'})

TASK [Create a VIP] **********************************************************************
changed: [localhost -> localhost]

PLAY RECAP *******************************************************************************
localhost                  : ok=4    changed=3    unreachable=0    failed=0    skipped=0

Additional Examples

You can find additional examples for leveraging this collection in this Example Repo.