with_items and increment

79 views
Skip to first unread message

Parth Patel

unread,
Oct 17, 2017, 5:15:04 PM10/17/17
to Ansible Project
I am trying to run this simple task where I want to increment  counter for "{{ esb_name }}_ESB_?" like "ABC_ESB_01, ABC_ESB_02 .....etc" until the loop is over.  How do I do that ?  I tried nested and other loops but was not able to do it.  Any suggestions ?

---
 - hosts: fuseesbdomhosts[0]
   remote_user: test
   become: yes
   become_method: sudo


 tasks:

     - debug:
         msg: "./client -a 8101 -h localhost -u admin -p admin 'fabric:container-create-child --profile {{ esb_name }}_CAML_PRFL {{ item }} {{ esb_name }}_ESB_?'"
       with_items:
        - "{{ groups['fuseesbdomhosts'] }}"

Kai Stian Olstad

unread,
Oct 18, 2017, 8:57:34 AM10/18/17
to ansible...@googlegroups.com
Not pretty, but you could try this

- debug:
msg: msg: "./client -a 8101 -h localhost -u admin -p admin
'fabric:container-create-child --profile {{ esb_name }}_CAML_PRFL {{
fuseesbdomhosts[item | int] }} {{ esb_name }}_ESB_{% if item | int > 9
%}{{ item }}{% else %}0{{ item }}{% endif %}'"
with_sequence: start=0 end={{ groups['fuseesbdomhosts'] | length -1 }}


--
Kai Stian Olstad

Parth Patel

unread,
Oct 18, 2017, 4:11:46 PM10/18/17
to Ansible Project
Thanks!
Reply all
Reply to author
Forward
0 new messages