I would use the dedicated find task. Apply a depth filter just in case. Something like this should do the trick:
- name: known hosts script play hosts: all become: true gather_facts: false tasks: - name: Find known hosts ansible.builtin.find: paths: - /root - /home patterns: known_hosts recurse: true depth: 3 register: found - name: Change known_host file ansible.builtin.script: cmd: foo.sh "{{ item }}" loop: "{{ found.files|map(attribute='path') }}" foo.sh is a script on your controller, adjacent to your playbook. On Tue, 21 May 2024 at 21:31, Dimitri Yioulos <dyiou...@gmail.com> wrote: > Good day. > > I need to make changes in the know_hosts files of users on various hosts. > I'll use a script to do the actual changes in known_hosts. I have the > following simple playbook, so far. It identifies users with known_host > files: > > > > > > > > > > > > > > > *---- hosts: all gather_facts: false become: yes tasks: - name: find > known hosts shell: find /root /home -type f -name known_hosts > register: known - debug: msg="{{ known.stdout }}"* > It produces the following output: > > > > > > > > > > > > > > > > > > > > > > > > *ok: [host1] => msg: |- /root/.ssh/known_hosts > /home/user1/.ssh/known_hosts /home/user2/.ssh/known_hosts > /home/user3/.ssh/known_hostsok: [host2] => msg: |- > /root/.ssh/known_hosts /home/user1/.ssh/known_hosts > /home/user2/.ssh/known_hosts /home/user3/.ssh/known_hosts > /home/user4/.ssh/known_hosts /home/user5/.ssh/known_hostsok: [host3] => > msg: /root/.ssh/known_hostsok: [host4] => msg: |- > /root/.ssh/known_hosts /home/user1/.ssh/known_hosts > /home/user2/.ssh/known_hosts /home/user3/.ssh/known_hosts~* > > I want to apply the script against the known_hosts file for each of the > identified users. How do I do that? > > -- > 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/623b5aa3-d20b-4648-b169-d2cce2b00cadn%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/623b5aa3-d20b-4648-b169-d2cce2b00cadn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAF8BbLa%2BEyEmOge1PAjG4gpHoxwwKbom%2BjTTxGabTowXez4JoA%40mail.gmail.com.