# Defined variable when value different

**URL:** <https://forum.ansible.com/t/defined-variable-when-value-different/29597>\
**Category:** Ansible Project\
**Created:** [February 1, 2019, 7:37pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597 "2019-02-01T19:37:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [February 1, 2019, 7:37pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/1 "2019-02-01T19:37:18Z")

</div>

Hi,

How defined variable value when other variable for different the 1.

Exemplo

vars:  
networkinterface\_number: 1

- name: Create network interface  
azure\_rm\_networkinterface:  
name: “interface{{networkinterface\_number}}”  
resource\_group: my\_resource  
virtual\_network\_name: my\_virtual\_network\_name  
subnet\_name: my\_subnet  
ip\_configurations:
- name: ipconfig1  
public\_ip\_address\_name: “{{ [get\_ip\_public.state.name](http://get_ip_public.state.name) }}”  
primary: True **# if “{{networkinterface\_number}}” for equal 1 primary True else False**  
with\_sequence: count=3 #“{{networkinterface\_number}}”

---

<div class="post-metadata">

**Author:** ![Keif\_Gwinn1](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Keif\_Gwinn1](https://forum.ansible.com/u/Keif_Gwinn1)\
**Post date:** [February 4, 2019, 10:55am UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/2 "2019-02-04T10:55:11Z")

</div>

multiple blocks with the when: keyword?

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [February 4, 2019, 12:10pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/3 "2019-02-04T12:10:05Z")

</div>

Hi Keif,

I need this example:

---

<div class="post-metadata">

**Author:** ![Keif\_Gwinn1](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Keif\_Gwinn1](https://forum.ansible.com/u/Keif_Gwinn1)\
**Post date:** [February 4, 2019, 12:22pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/4 "2019-02-04T12:22:26Z")

</div>

- name: Create Primary network interface  
azure\_rm\_networkinterface:  
name: “interface{{item}}”  
resource\_group: my\_resource  
virtual\_network\_name: my\_virtual\_network\_name  
subnet\_name: my\_subnet  
ip\_configurations:

- name: ipconfig{{item}}  
public\_ip\_address\_name: “{{ [get\_ip\_public.state.name](http://get_ip_public.state.name) }}”  
primary: True  
with\_sequence: start=0 end=0

- name: Create Additional network interface  
azure\_rm\_networkinterface:  
name: “interface{{item}}”  
resource\_group: my\_resource  
virtual\_network\_name: my\_virtual\_network\_name  
subnet\_name: my\_subnet  
ip\_configurations:

- name: ipconfig{{item}}  
public\_ip\_address\_name: “{{ [get\_ip\_public.state.name](http://get_ip_public.state.name) }}”  
primary: False  
with\_sequence: start=1 end=networkinterface\_number

Would be my suggestion, it looks like it’d need some work around the IP address assignments.

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [February 4, 2019, 12:25pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/5 "2019-02-04T12:25:55Z")

</div>

OK, but have 10 network?

This network interface number is dynamic. The one interface is TRUE, more ins FALSE

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [February 4, 2019, 12:36pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/6 "2019-02-04T12:36:18Z")

</div>

Ok, the first interface TRUE and 0\> is false.

How to with\_sequence: start=1 end= **“networkinterface\_number - 1”**

---

<div class="post-metadata">

**Author:** ![Keif\_Gwinn1](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Keif\_Gwinn1](https://forum.ansible.com/u/Keif_Gwinn1)\
**Post date:** [February 4, 2019, 1:07pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/7 "2019-02-04T13:07:11Z")

</div>

- name: Create Additional network interface  
azure\_rm\_networkinterface:  
name: “interface{{item}}”  
resource\_group: my\_resource  
virtual\_network\_name: my\_virtual\_network\_name  
subnet\_name: my\_subnet  
ip\_configurations:
- name: ipconfig{{item}}  
public\_ip\_address\_name: “{{ [get\_ip\_public.state.name](http://get_ip_public.state.name) }}”  
primary: False  
with\_sequence: start=1 end=networkinterface\_numberminus1  
vars:  
networkinterface\_numberminus1: networkinterface\_number - 1

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [February 4, 2019, 1:21pm UTC](https://forum.ansible.com/t/defined-variable-when-value-different/29597/8 "2019-02-04T13:21:46Z")

</div>

Thanks, resolved.
