Defined variable when value different

27 views
Skip to first unread message

Rafael Tomelin

unread,
Feb 1, 2019, 2:37:38 PM2/1/19
to ansible...@googlegroups.com
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 }}"
        primary: True  # if "{{networkinterface_number}}" for equal 1 primary True else False
  with_sequence: count=3 #"{{networkinterface_number}}"

--
Atenciosamente,

Rafael Tomelin
Tel.: 51-84104084
Skype: rafael.tomelin

LPI ID: LPI000191271

Keif Gwinn

unread,
Feb 4, 2019, 5:55:25 AM2/4/19
to ansible...@googlegroups.com
multiple blocks with the when: keyword?

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGEUqbCOC35%3DisWmP65ZJ9kMpjgXNVJSV5uLCmS2RocVr00cqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Keif Gwinn

Rafael Tomelin

unread,
Feb 4, 2019, 7:10:25 AM2/4/19
to ansible...@googlegroups.com
Hi Keif,

I need this example:

---
- hosts: localhost
  vars:
    networkinterface_number: 5

  tasks:
      - debug: "msg='network {{ myvar }} '"
        vars:
          myvar: "{{ 'True' if ( item == 1) else 'False' }}"
        with_sequence: count="{{networkinterface_number}}"

But, myvar not replace in loop with_sequence.




For more options, visit https://groups.google.com/d/optout.


--

Keif Gwinn

unread,
Feb 4, 2019, 7:22:40 AM2/4/19
to ansible...@googlegroups.com
- 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 }}"
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 }}"
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. 


For more options, visit https://groups.google.com/d/optout.


--
Keif Gwinn

Rafael Tomelin

unread,
Feb 4, 2019, 7:26:16 AM2/4/19
to ansible...@googlegroups.com
OK, but have 10 network?

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


For more options, visit https://groups.google.com/d/optout.

Rafael Tomelin

unread,
Feb 4, 2019, 7:36:39 AM2/4/19
to ansible...@googlegroups.com
Ok, the first interface TRUE and 0> is false.

How to   with_sequence: start=1 end="networkinterface_number - 1"


For more options, visit https://groups.google.com/d/optout.

Keif Gwinn

unread,
Feb 4, 2019, 8:07:31 AM2/4/19
to ansible...@googlegroups.com
- 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 }}"
primary: False
with_sequence: start=1 end=networkinterface_numberminus1
vars:
networkinterface_numberminus1: networkinterface_number - 1



For more options, visit https://groups.google.com/d/optout.


--
Keif Gwinn

Rafael Tomelin

unread,
Feb 4, 2019, 8:22:09 AM2/4/19
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages