- name: look for backup files

      find:

        paths: /tmp

        recurse: false

        file_type: 'file'

        patterns: '^{{ item.filename }}\.[0-9]{6}.*$'

        use_regex: true

      loop: ['backup']

      register: found


    - name: get list of files

      set_fact:

        files: "{{ found.results | json_query('[*].files[*][]') }}"


    - name: show list of files

      debug: var=item.path

      loop: "{{ files }}"


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Mar 13, 2023, at 1:11 PM, 'Rowe, Walter P. (Fed)' via Ansible Project 
<ansible-project@googlegroups.com> wrote:

You are not registering the product of the task.

find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}
register: found

You then need to look at found.files (a list) to see what is found. This is 
documented in the ansible find module.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Mar 13, 2023, at 12:39 PM, Hiero-nymo <jer.m.me...@gmail.com> wrote:

Hi everyone,

I've tried to using a variable in find module by pattern by it doesn't seems to 
work. Here's below a example. I also looked at another solution with set_facts 
but I doesn't run too.
I want to list all the backup files in a directory. The files have a timestamp 
and it's filename will be defined by variable.
Does anyone have an idea how should I proceed? or in which way?

Thanks in advance for your help

Here's the variables:
---
file:
  - filename: backup
    state: present
[...]

Here's the task:
---
[...]
find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}

--
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 
ansible-project+unsubscr...@googlegroups.com<mailto:ansible-project+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3419395b-36b0-4195-9278-de959fa763can%40googlegroups.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F3419395b-36b0-4195-9278-de959fa763can%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cfa441b724f7344dd4f5308db23e60f14%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638143243221107121%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=B7MfItZ589Vi8qf9375GywGYBVTJyQc5n4u7Unvcg%2Bw%3D&reserved=0>.


--
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 
ansible-project+unsubscr...@googlegroups.com<mailto:ansible-project+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7E9B8E33-5171-4B7B-80D0-8AAEEA6A7E44%40nist.gov<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F7E9B8E33-5171-4B7B-80D0-8AAEEA6A7E44%2540nist.gov%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cfa441b724f7344dd4f5308db23e60f14%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638143243221107121%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Y%2BYq%2BehKuEBAHv6VpE0x0rZgwffq353SjFpD3j%2B8f%2Fk%3D&reserved=0>.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/D7179F38-74CE-4A16-B296-60874B87A5AF%40nist.gov.

Reply via email to