# Use of register variable in following play(s)

**URL:** <https://forum.ansible.com/t/use-of-register-variable-in-following-play-s/38790>\
**Category:** Ansible Project\
**Created:** [May 21, 2024, 7:31pm UTC](https://forum.ansible.com/t/use-of-register-variable-in-following-play-s/38790 "2024-05-21T19:31:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [May 21, 2024, 7:31pm UTC](https://forum.ansible.com/t/use-of-register-variable-in-following-play-s/38790/1 "2024-05-21T19:31:13Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 21, 2024, 8:06pm UTC](https://forum.ansible.com/t/use-of-register-variable-in-following-play-s/38790/2 "2024-05-21T20:06:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [May 21, 2024, 8:34pm UTC](https://forum.ansible.com/t/use-of-register-variable-in-following-play-s/38790/3 "2024-05-21T20:34:20Z")

</div>

Thank you, Dick!
