On Sat, 23 Mar 2024 11:12:20 -0400
Michael DiDomenico <mdidomeni...@gmail.com> wrote:

> ... i was hoping there was a more elegant way which
> didn't need a series of finds

The complexity is a consequence of you requirement to
"rehash the directory if the counts aren't equal". You
can't compare *counts* without at least two *finds*. The
elegant way is a single *find* and iteration of all
certificates

    - find:
        paths: /tmp/ansible/certs
        patterns: '*.crt'
      register: out_crt

    - file:
        state: link
        src: /tmp/ansible/certs/{{ item }}.crt
        dest: /tmp/ansible/certs/{{ item }}.0
      loop: "{{ out_crt.files |
                json_query('[].path') |
                map('basename') |
                map('splitext') |
                map('first') }}"

This is, however, less efficient. The options are limited
because *file* doesn't work with wildcards. If you don't
care about idempotency and the changed/failed status
*shell* also does the job

    - shell: |
        cd /tmp/ansible/certs &&
        for i in *.crt; do ln -s $i ${i%.crt}.0; done
      failed_when: false
      changed_when: false

You can write advanced scripts or custom filters that would
do what you want.

-- 
Vladimir Botka

-- 
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/20240323215054.47a4d106%40planb.

Attachment: pgpWlNVNvqSc8.pgp
Description: OpenPGP digital signature

Reply via email to