I have the following files in my tmp directory
root@ansible:/tmp/test$ ls /tmp/test/
file1 file2 file3
I also have the following playbook which is modeled after this
vars:
exclude_files: file1
tasks:
- name: check files
shell: ls -l /tmp/test
register: capture
- name: remove files
file: path=/tmp/test/{{item}} state=absent
with_items: capture.stdout_lines
when: item not in exclude_files
- name: debug variable
debug: msg={{exclude_files}}
Unfortunately the second task isn't removing file2,file3
. Instead it's treating the registered variable as a file.
ok: [172.16.2.3] => (item=capture.stdout_lines) => {
"changed": false,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"content": null,
"delimiter": null,
"diff_peek": null,
"directory_mode": null,
"follow": false,
"force": false,
"group": null,
"mode": null,
"original_basename": null,
"owner": null,
"path": "/tmp/test/capture.stdout_lines",
"recurse": false,
"regexp": null,
"remote_src": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"state": "absent",
"unsafe_writes": null,
"validate": null
}
},
"item": "capture.stdout_lines",
"path": "/tmp/test/capture.stdout_lines",
"state": "absent"
Any idea why this code isn't working? I am using ansible 2.3.