loop control for with_together

27 views
Skip to first unread message

Diyawary

unread,
May 12, 2020, 5:42:13 AM5/12/20
to Ansible Project
Hi team,
could you please help me how to give two loop_vars for corresponding list for with_together module

my requirement is ,i am calling a role and where looping with_togetjher
- include_role:
          name: validatetcp_port
   when: item.0 ==  'tcp'
   with_together:
      -  "{{ proto}}"
      -   "{{ svc_port}}"
   loop_control:
      loop_var: svc_port

 this is not working .my inner yml is only utilizing svc_port  and for when condition I need  item of proto  list. in my inner yml already a loop so without loop control it is not working. in current loop_var for inner yml its passing whole list of svc_port as a single item.
 so please suggest me how i can apply loop_vars



Dick Visser

unread,
May 12, 2020, 6:12:43 AM5/12/20
to ansible...@googlegroups.com
You declare 'loop_var: svc_port' but that var already exists as one of the two variables of with_together. That won't work, you need to pick some other name.
Also, loop_var in the context of with_together will be a list of two vars (values from proto and svc_port).



--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9490a147-8917-4c6f-a8eb-cca5cfd778c6%40googlegroups.com.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Diyawary

unread,
May 12, 2020, 11:57:08 AM5/12/20
to Ansible Project
I tried with the other loop_var name but didnt worked. my issues is for inner yml i wanted only port list items pass ,when using a loop_var it is passing both list items . Please suggets how i can achieve this.

Dick Visser

unread,
May 12, 2020, 12:17:00 PM5/12/20
to ansible...@googlegroups.com
Send the inner yml

--
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.

Diyawary

unread,
May 13, 2020, 5:10:22 AM5/13/20
to Ansible Project
Hi ,

Please find below my inner yml
- name: Checking TCP Service objects
      uri:
        url: "https://{{hostname}}/web_api/show-objects"
        validate_certs: False
        method: POST
        headers:
          x-chkp-sid: "{{ login.json.sid }}"
        body:
          filter: "{{item}}"
          type: "service-tcp"
        body_format: json
      register: check_host_result

    - name: Checking if TCP Service Object already exists
      set_fact:
        item_tcptype_exists: true
        svc_name: "{{ item['name'] }}"
      with_items: "{{ check_host_result.json.objects  }}"
      when:
        #- item['port'] == "{{svc_port}}"
        -  item['port'] == "{{port}}"
        -  item['type'] is defined
        -  item['type'] == "service-tcp"
    - debug:
        msg: "Service  Object exists with name [{{svc_name}}]"

and also other api call on the output of above set_facts in this inner yml


On Tuesday, 12 May 2020 11:17:00 UTC-5, Dick Visser wrote:
Send the inner yml 
On Tue, 12 May 2020 at 17:57, Diyawary <yogesh...@gmail.com> wrote:
I tried with the other loop_var name but didnt worked. my issues is for inner yml i wanted only port list items pass ,when using a loop_var it is passing both list items . Please suggets how i can achieve this.


On Tuesday, 12 May 2020 04:42:13 UTC-5, Diyawary wrote:
Hi team,
could you please help me how to give two loop_vars for corresponding list for with_together module

my requirement is ,i am calling a role and where looping with_togetjher
- include_role:
          name: validatetcp_port
   when: item.0 ==  'tcp'
   with_together:
      -  "{{ proto}}"
      -   "{{ svc_port}}"
   loop_control:
      loop_var: svc_port

 this is not working .my inner yml is only utilizing svc_port  and for when condition I need  item of proto  list. in my inner yml already a loop so without loop control it is not working. in current loop_var for inner yml its passing whole list of svc_port as a single item.
 so please suggest me how i can apply loop_vars



--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages