Use of register variable in following play(s)

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:

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.

Thank you, Dick!