Hi Rafael, On Thu, 19 Dec 2019 00:40:24 -0300 Rafael Tomelin <[email protected]> wrote:
> I want to do loop in the dict variable appliance and in variable have var
> count. This count I should like loop count.
>
> appliances:
> fw01:
> count: 2
> vmname: name
> image: redhat
> os_type: Linux
> data_disks:
> - lun: 0
> disk_size_gb: 128
> managed_disk_type: Standard_LRS
>
> - name: virtual_machine
> debug:
> msg: "{{ item.key }} - {{ item.value.count }}"
> with_dict:
> - "{{ virtual_machine }}"
> with_sequence: start=0 end="{{ item.value.count }}"
>
> but return this error:
> ERROR! duplicate loop in task: sequence
>
> How can create this loop?
It's possible to *include_tasks* and create nested loops. For this purpose
it's necessary to "Define inner and outer variable names with loop_var"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#defining-inner-and-outer-variable-names-with-loop-var
For example the playbook
$ cat playbook.yml
- hosts: master
tasks:
- include_tasks: create-vm.yml
loop: "{{ appliances|dict2items }}"
with this included file
$ cat create-vm.yml
- name: virtual_machine
debug:
msg: "{{ item.key }} - {{ inner_item }}"
with_sequence: start=0 end="{{ item.value.count - 1 }}"
loop_control:
loop_var: inner_item
should give
ok: [master] => (item=0) => {
"msg": "fw01 - 0"
}
ok: [master] => (item=1) => {
"msg": "fw01 - 1"
}
Cheers,
-vlado
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20191219093343.1d504e4c%40gmail.com.
pgpbD0nK4IVb0.pgp
Description: OpenPGP digital signature
