On 24. april 2017 21:46, Cann wrote:
Hello Everyone
I have been using Ansible for about a year now and I can't wrap my head
around on idea of "registered variables"
I bought books, read online docs and looked at examples... but I still
can't use this important future properly.
You are almost there.
Let me give you a example:
I want to find files that are older than 7 days:
- name: Find backups that are older than 7 days
find: paths="/db-backups" age="7d"
register: list_of_db_backups
and I want to delete the files that I have found:
- name: Cleanup backups that are older than 7 days
file:
name: "{{ item.path }}"
state: absent
with_items: list_of_db_backups.files
Writing variable without {{ }} in with_items was allowed in older
version of Ansible, in newer version {{ }} is required.
If you leave them out it's treated literally as the string
"list_of_db_backups.files".
So with
with_items: "{{ list_of_db_backups.files }}"
your code should work.
--
Kai Stian Olstad
--
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/684a39fe-bc3d-2177-9628-06771aafddb1%40olstad.com.
For more options, visit https://groups.google.com/d/optout.