I have a ansible role with the simple task of a finding some files in multiple paths and a debug statement showing what it did find, looks like this:
- name: "find smth"
find:
paths: "{{ search_path }}"
file_type: file
patterns: "*.gz"
recurse: no
loop_control:
loop_var: search_path
loop: "{{ search_paths }}"
register: find_result
- debug:
msg: "{{ file_path }}"
loop_control:
loop_var: file_path
loop: "{{ find_result.results | map(attribute='files') | sum(start=[]) | map(attribute='path') | list }}"
This works when i use a playbook BUT it does not work when i call the role via commandline like this:
ansible HOST -u REMOTE_USER -m include_role -a name=ROLE_NAME -e '{"include": {"step1": "06_test"}}' -e '{"search_paths":["/tmp","/opt/tmp"]}'
main.yml (just to explain the step1 include):
- include: "{{ item.value }}.yml"
loop: "{{ lookup('dict', include, wantlist=True) }}"
In this case the debug task always prints:
HOST | SUCCESS => {
"msg": "All items completed"
}
Which is the result message of the loop, the registered find_result structure is there but i can not access it via the loop in the debug task. Accessing a value however works (e.g. msg: "{{ find_result.results[0].files[0].path }}").
I am using ansible in version 2.9.9 with python 3.5.7 on debian stretch. The tasks above are only a broke down test of the real scenario.