dictionary - How to loop in Ansible $var number of times? -


i want run loop in ansible number of times defined in variable. possible somehow?

imagine list of servers , want create numbered files on each server. these values defined in vars.yml:

server_list:   server1:     name: server1     os: linux     num_files: 3   server2:     name: server2     os: linux     num_files: 2 

the output desire files /tmp/1, /tmp/2 , /tmp/3 created on server1, /tmp/1 , /tmp/2 created on server2. have tried write playbook using with_nested, with_dict , with_subelements can't seem find way to this:

- hosts: "{{ target }}"    tasks:      - name: load vars       include_vars: vars.yml      - name: create files       command: touch /tmp/{{ loop_index? }}       with_dict: {{ server_list[target] }}       loop_control:         loop_var: {{ item.value.num_files }} 

if needed create 50 files on each server can see how if have list variable each server 50 items in list numbers 1 50, self defeating use of ansible.

there chapter in docs: looping on integer sequences

for task:

- file:     state: touch     path: /tmp/{{ item }}   with_sequence: start=1 end={{ server_list[target].num_files }} 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -