Looping over directories instead of files ?

I have a set of bare git directories stored as /home/git/XXX.git.

I would like to synchronize all the XXX.git directories with a remote server using ansible.
But this is apparently not possible.

In my gitsrv role’s main.yml I have defined the following task:

  • debug: msg=“src=‘{{item }}’”
    with_fileglob:

  • /home/git/*.git
    tags: test

  • name: Restore repositories
    synchronize: src=“{{ item }}” mode=push dest=“/home/git”
    with_fileglob:

  • /home/git/*.git
    tags: restore

Both command do nothing because the blob set contains no file. It contains only directories and and with_fileblob iterates only on files.

How could I synchronize the XXX.git directories with the remote server ?

with_pipe: find /home/git/*.git -type d

Thank you very much Brian. This was incredibly useful.

I had to do a small change to your suggested command otherwise it lists all the directories found recursively. I added the maxdepth option.
This is for people looking later for the answer:

with_pipe: find /home/git/*.git -type d -maxdepth 0

In fact it is still not right. The correct loop instruction is

with_lines: find /home/git/*.git -type d -maxdepth 0

This will make one iteration per command output line and assign it to item.

if you only want the .gits:

with_lines: find /home/git/ -name '*.git' -type d -maxdepth 0

Yes I only want the .git. Indeed your way to invoke find is more correct. However it still need a change to work on my Ubuntu computer. This one worked.

find /home/git/ -maxdepth 1 -name “*.git” -type d

The maxdepth option should be moved to front and its value should be 1. Your way to invoke find is indeed better than mine