Hello,
Using ansible v1.9.4, I am having an issue using set_facts if combining
with_items and when conditional. I am tackling a new use case for our
environment and have not tested with this any other version, since 1.9.4 is
the production version.
When 'when' is not used, the 'all_files' fact lists the basename properly.
---
- hosts: 127.0.0.1
connection: local
gather_facts: no
tasks:
- set_fact:
files_fact: "{{ item | basename }}"
with_items: files
# when: "{{ item | search('^/tmp/foo.*') }}"
register: files_result
- debug:
msg: "{{ files_result }}"
- set_fact:
all_files: "{{ files_result.results |
map(attribute='ansible_facts.files_fact') | list }}"
vars:
files:
- /tmp
- /tmp/foo1
- /tmp/foo2
- /tmp/bar1
TASK: [set_fact ]
*************************************************************
ok: [127.0.0.1] => {"ansible_facts": {"all_files": ["tmp", "foo1", "foo2",
"bar1"]}}
When the 'when' is used to match the search string, for values that are
'skipped' due positive match, the files_result.results contains for the
matching items
{
"changed": false,
"skipped": true
}
Thus causing an error since the results list does not contain
'ansible_facts'
TASK: [set_fact ]
*************************************************************
fatal: [127.0.0.1] => One or more undefined variables: 'dict object' has no
attribute 'ansible_facts'
The {{ files }} variable is dynamic in my use case but I have been testing
with static values as listed.
Thanks
Jason
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7fb2b7e4-705d-4bb9-ba58-f57954b410ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.