Reputation: 21
Ansible playbook with_subelements error with 3 levels.
My Config looks like
---
Firstlevel:
- fl_number: fln1
fl_data: fld1
Secondlevel:
- sl_number: sln_f1_1
sl_data: sld_f1_1
Thirdlevel:
- tl_number: tln_s1_f1_1
tl_data: tld_s1_f1_1
- tl_number: tln_s2_f1_2
tl_data: tld_s2_f1_2
The Ansible playbook is
>cat test_threelevels.yml
---
- hosts: localhost
gather_facts: no
vars_files:
- ../vars/testConfig-var.yml
tasks:
- name: DebugWorks
debug: msg="{{ item.1.Thirdlevel }}"
with_subelements:
- Firstlevel
- Secondlevel
- name: DebugDoesNotWork
debug: msg=" Sub element Thirdlevel test"
with_subelements:
- Firstlevel
- Secondlevel
- Thirdlevel
When it is executed with ansible-playbook -v test_threelevels.yml
the task "DebugWorks" works but the task "DebugDoesNotWork" dosent.
Output TASK: [DebugDoesNotWork] ****************************************************** fatal: [localhost] => subelements lookup expects a list of two items, first a dict or a list, and second a string
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
Need help in understanding if this is the right way to do and why it does not work.
Open to any suggestions.
Thanks.
Upvotes: 2
Views: 5049
Reputation: 17514
The error description at least vaguely says what's meant. :)
Refer to the code to see exactly the error means here. terms
is the list you pass.
if not isinstance(terms, list) or not 2 <= len(terms) <= 3:
In short: You can only go 2 levels, not 3.
The documentation does say clearly:
Optionally, you can add a third element to the subelements list, that holds a dictionary of flags.
Upvotes: 2