need help with nested loop

21 views
Skip to first unread message

eric sandgren

unread,
Jun 5, 2019, 2:29:25 AM6/5/19
to Ansible Project
First I'm a sysadmin not a developer I often use ansible to set up things in f5 -ltm i often need to add several hosts to a number of pools. The loadbalancing setup in f5 products in a glance consist of av VIP (virtual server) that is linked to a Pool containing one or more physical servers.
I get stuck in how to set up the loop, i define this first
var_node:
       - { host: 1.2.3.4, name: server1.com }   
       - { host: 1.2.3.5, name: server2.com }
var_pool:
       - { pool: pool1, port: 80 }
       - { pool: pool2, port: 8080 }
       - { pool: pool3, port: 443 }

The module ii'm trying to use

- name: add nodes to pools
      bigip_pool_members:
        provider: "{{ provider }}"
        partition: "{{ partition }}"
        pool:{{ item.pool }}          "here I want to loop var_pool
        name: "{{ item.name }}    "here I want to loop var_node"
        port: "{{ item.port}}           "and again ....var_pool"
     loop: ?????

I realize I'm probably on a dead end thinking this way any good input from a developer-mind would be extremely appreciated  

/Eric

Kai Stian Olstad

unread,
Jun 5, 2019, 3:19:32 AM6/5/19
to ansible...@googlegroups.com

J Hawkesworth

unread,
Jun 6, 2019, 2:59:06 AM6/6/19
to Ansible Project
Yeah with_together would work in your scenario.

Strangely I was looking to do something similar but the very helpful F5 team provided me with this, so I thought I'd share it.

I was trying to find a way to switch the pool members between 2 sets of servers.

One difference here is we're associating the port with the pool member, rather than the pool in your case.

vars:
   f5_pools:
      middleware:
        red:
          - host: 192.168.27.1
            port: 80
        green:
          - host: 192.168.27.2
            port: 80
      webfront:
        red:
          - host: 192.168.27.1
            port: 80
          - host: 192.168.27.2
            port: 80
        green:
          - host: 192.168.28.1
            port: 80
          - host: 192.168.28.2
            port: 80

  tasks:

  - name: RED
    bigip_pool_member:
      pool: "{{ item }}"
      aggregate: "{{ f5_pools[item].red }}"
      replace_all_with: yes
      provider: "{{ provider }}"
    delegate_to: localhost
    loop: "{{ f5_pools.keys() }}"
    tags: red
 
  - name: GREEN
    bigip_pool_member:
      pool: "{{ item }}"
      aggregate: "{{ f5_pools[item].green }}"
      replace_all_with: yes
      provider: "{{ provider }}"
    delegate_to: localhost
    loop: "{{ f5_pools.keys() }}"
    tags : green
Reply all
Reply to author
Forward
0 new messages