F5 Policy with Multiple Rules

I’m having trouble getting my variables correct to add multiple rules to a single policy. I need a loop because I will be adding multiple VIP with different policy names and multiple rules per policy. The module I’m using is bigip_policy_rule.

- name: Add multiple rules to the new policy
  bigip_policy_rule:
    policy: Policy-Foo  <------ I want to use a variable for the policy name as well
    name: "{{ item.name }}"
    conditions: "{{ item.conditions }}"
    actions: "{{ item.actions }}"
    provider:
      server: lb.mydomain.com
      user: admin
      password: secret
  delegate_to: localhost
  loop: "{{ rules }}"
Variables file looks like this:
rules:

By adding an extra key:

rules:
    - name: rule1
      policy: Policy-Foo
      actions:
        - type: forward
          pool: pool-svrs
      conditions:
        - type: http_uri
          path_starts_with: /euro
    - name: rule2
      policy: Policy-Bar
      actions:
        - type: forward
          pool: pool-svrs
      conditions:
        - type: http_uri
          path_starts_with: /HomePage/

Your task would be looking like this:

- name: Add multiple rules to the new policy
  bigip_policy_rule:
    policy: "{{ item.policy }}"
    name: "{{ item.name }}"
    conditions: "{{ item.conditions }}"
    actions: "{{ item.actions }}"
    provider:
      server: lb.mydomain.com
      user: admin
      password: secret
  delegate_to: localhost
  loop: "{{ rules }}"

Dick

Thanks you for the help. I guess I was maker it harder than it was. Its all working now.