Why not structure your data like this:

---
- hosts: all
  vars:
   provider:
     password: Password
     server: IP
     user: username
     validate_certs: no
     server_port: port
  mapping: # This is new and might be stored elsewhere :)
    server1.example.com: 192.0.2.1
    server2.example.com: 192.0.2.2
    server3.example.com: 192.0.2.3


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

    - name: Add members to pool
     bigip_pool_member:
       provider: "{{ provider }}"
       description: "webserver {{ item.key }}"
       host: "{{ item.value }}"
       name: "{{ item.key }}"
       pool: "{{ service }}"
       port: "{{ lbport }}"
     loop:"{{ mapping|flatten() }}"

Regards,
--
Jon "The Nice Guy" Spriggs
@jontheniceguy everywhere...
https://jon.sprig.gs


On Sat, 23 Feb 2019 at 14:29, Spencer Webb <[email protected]> wrote:

> Hi all,
>
> I've got a playbook that uses variables to create a load balanced pool and
> the required members on our test F5 BigIP.
>
> I've got the basics working without issue, however, the number of members
> of a pool for any given run is not a fixed number and could range from 1 up
> to say 10.
>
> I'm running Ansible Tower and invoking the template via tower-cli. I'm
> using extra-vars to provide realip and realserver and looped through. The
> default values are set to null so I was hoping to loop through the list
> until a null value for item.host is observed. I'm not sure if this is the
> best way to deal with this, it's the first time that I've tried to deal
> with variable lists that are not fixed in number.
>
> Here's my current code, any help would be greatly appreciated.
>
> Cheers
> Spence
>
> ---
>
> - name: Create a VIP, pool and pool members
>  hosts: all
>  connection: local
>
>   vars:
>    provider:
>      password: Password
>      server: IP
>      user: username
>      validate_certs: no
>      server_port: port
>
>   tasks:
>    - name: Create a pool
>      bigip_pool:
>        provider: "{{ provider }}"
>        lb_method: ratio-member
>        name: "{{ service }}"
>        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: "{{ service }}"
>        port: "{{ lbport }}"
>      loop:
>        - { host: "{{ realip1 }}",  name: "{{ realserver1 }}" }
>        - { host: "{{ realip2 }}",  name: "{{ realserver2 }}" }
>        - { host: "{{ realip3 }}",  name: "{{ realserver3 }}" }
>        - { host: "{{ realip4 }}",  name: "{{ realserver4 }}" }
>        - { host: "{{ realip5 }}",  name: "{{ realserver5 }}" }
>        - { host: "{{ realip6 }}",  name: "{{ realserver6 }}" }
>        - { host: "{{ realip7 }}",  name: "{{ realserver7 }}" }
>        - { host: "{{ realip8 }}",  name: "{{ realserver8 }}" }
>        - when: item.host != ""
>        - delegate_to: localhost
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/cf8e3969-eeaf-422b-9fbd-4ca36d19d660%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/cf8e3969-eeaf-422b-9fbd-4ca36d19d660%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOrCWesJFMjWxPga0XSp9zDgEHOyqga8vdqXt_EmZ2cUTOOD4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to