Example Playbook and Setup v2

Follow this tutorial to create a virtual service, pool, monitor, and pool members using the F5 Automation Toolchain’s AS3 extension.

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

Note

You must have AS3 installed on your target BIG-IP for this example to work. If you are not familiar with AS3, see the AS3 documentation.

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 are specifying our BIG-IP connection information within the playbook itself.

First, put the following text in a new file located at inventory/hosts.

bigip

Create the AS3 Declaration file

The AS3 declaration file is the configuration definition for what you want setup on your BIG-IP.

Create a file called as3.json in your current working directory, and place the following content in it.

{
  "class": "AS3",
  "action": "deploy",
  "persist": true,
  "declaration": {
    "class": "ADC",
    "schemaVersion": "3.22.0",
    "id": "id",
    "label": "WebApp",
    "ansible": {
      "class": "Tenant",
      "A1": {
        "class": "Application",
        "web": {
          "class": "Service_HTTP",
          "virtualAddresses": ["10.1.2.3"],
          "virtualPort": 80,
          "pool": "web_pool"
        },
        "web_pool": {
          "class": "Pool",
          "monitors": [{"use": "http_mon"}],
          "members": [
            {
              "servicePort": 8080,
              "serverAddresses": [
                "10.2.2.3"
              ]
            }
          ]
        },
        "http_mon": {
            "class": "Monitor",
            "monitorType": "http",
            "receive": "I AM UP"
        }
      }
    }
  }
}

The Playbook

The following playbook will: * Run the bigip_as3_deploy module using the AS3 declaration you created in the previous step.

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

---
- name: AS3
  hosts: bigip
  connection: httpapi
  gather_facts: false

  # Connection Info
  vars:
    ansible_host: bigip-hostname
    ansible_user: admin
    ansible_httpapi_password: SuperSecret
    ansible_httpapi_port: 443
    ansible_network_os: f5networks.f5_bigip.bigip
    ansible_httpapi_use_ssl: yes
    ansible_httpapi_validate_certs: no

  tasks:

    - name: Deploy or Update AS3
      f5networks.f5_bigip.bigip_as3_deploy:
          content: "{{ lookup('file', 'as3.json') }}"
      tags: [ deploy ]

Run the playbook

Now you can run the playbook using the following command:

ansible-playbook -i inventory/hosts playbook.yaml

If you followed the steps correctly, you should see output similar to the following.

...

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

Note

Since AS3 is declarative, updating your application is as easy as modifying the JSON file and running the playbook again. You do not need to maintain logic in Ansible anymore for dependency mapping of pools to virtuals to profiles, etc. AS3 handles this logic for you.

Additional Examples

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