Forum Discussion

  • This is an example of how to set up a pool and add members using the loop method and Ansible environment variables.

    F5 host needs to be defined in an inventory file 'inventory/hosts'

    [f5]
    192.168.1.1
    

    Playbook:

    ---
    - name: Setup
      hosts: f5
      connection: local
      gather_facts: True
    
      vars:
        f5Provider:
          server: "{{inventory_hostname}}"
          user: "admin"
          password: "admin"
          validate_certs: no
          transport: rest
        nodelist:
          - {name: 'test01', address: '8.8.8.8', priority_group: 1, state: 'present'}
          - {name: 'test02', address: '8.8.4.4', priority_group: 1, state: 'present'}
    
      environment:
          F5_SERVER: "{{ inventory_hostname }}"
          F5_USER: "{{ f5Provider.user }}"
          F5_PASSWORD: "{{ f5Provider.password }}"
          F5_VALIDATE_CERTS: "{{ f5Provider.validate_certs }}"
          F5_SERVER_PORT: "{{ f5Provider.server_port }}"
    
      tasks:
        - name: Add pool 'test_pool'
          bigip_pool:
            lb_method: least-connections-member
            name: test_pool
            monitor_type: single
            monitors:
              - /Common/gateway_icmp
            priority_group_activation: 0
          delegate_to: localhost
          notify: Save configuration
    
        - name: Add nodes
          bigip_node:
            address: "{{ item.address }}"
            name: "{{ item.name }}"
          loop: "{{ nodelist }}"
          delegate_to: localhost
          notify: Save configuration
    
        - name: Add pool members to Pool 'test_pool'
          bigip_pool_member:
            pool: test_pool
            address: "{{ item.address }}"
            name: "{{ item.name }}"
            port: 53
            priority_group: "{{ item.priority_group }}"
            state: "{{ item.state }}"
          loop: "{{ nodelist }}"
          delegate_to: localhost
          notify: Save configuration