# F5 Policy with Multiple Rules

**URL:** <https://forum.ansible.com/t/f5-policy-with-multiple-rules/32577>\
**Category:** Ansible Project\
**Created:** [April 1, 2020, 12:20am UTC](https://forum.ansible.com/t/f5-policy-with-multiple-rules/32577 "2020-04-01T00:20:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharon\_Day](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Sharon\_Day](https://forum.ansible.com/u/Sharon_Day)\
**Post date:** [April 1, 2020, 12:20am UTC](https://forum.ansible.com/t/f5-policy-with-multiple-rules/32577/1 "2020-04-01T00:20:28Z")

</div>

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.

```auto
- 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 }}"

```

```auto
Variables file looks like this:

```

```auto
rules:

```

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 1, 2020, 5:24am UTC](https://forum.ansible.com/t/f5-policy-with-multiple-rules/32577/2 "2020-04-01T05:24:55Z")

</div>

By adding an extra key:

rules:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: rule1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;policy: Policy-Foo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actions:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- type: forward  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool: pool-svrs  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conditions:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- type: http\_uri  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path\_starts\_with: /euro  
&nbsp;&nbsp;&nbsp;&nbsp;- name: rule2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;policy: Policy-Bar  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actions:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- type: forward  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pool: pool-svrs  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conditions:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- type: http\_uri  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path\_starts\_with: /HomePage/

Your task would be looking like this:

- name: Add multiple rules to the new policy  
&nbsp;&nbsp;bigip\_policy\_rule:  
&nbsp;&nbsp;&nbsp;&nbsp;policy: "{{ item.policy }}"  
&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item.name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;conditions: "{{ item.conditions }}"  
&nbsp;&nbsp;&nbsp;&nbsp;actions: "{{ item.actions }}"  
&nbsp;&nbsp;&nbsp;&nbsp;provider:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server: lb.mydomain.com  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user: admin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: secret  
&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;loop: "{{ rules }}"

Dick

---

<div class="post-metadata">

**Author:** ![Sharon\_Day](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Sharon\_Day](https://forum.ansible.com/u/Sharon_Day)\
**Post date:** [April 24, 2020, 1:55am UTC](https://forum.ansible.com/t/f5-policy-with-multiple-rules/32577/3 "2020-04-24T01:55:13Z")

</div>

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