Thank you, Dick!

On Tuesday, May 21, 2024 at 4:07:19 PM UTC-4 Dick Visser wrote:

> 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 <[email protected]> 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 [email protected].
>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/159a3001-7fbc-4ad2-b91f-3e95f9eb554dn%40googlegroups.com.

Reply via email to