# Use a variable with run\_once

**URL:** <https://forum.ansible.com/t/use-a-variable-with-run-once/44710>\
**Category:** Guides, FAQs & Howtos\
**Tags:** howto\
**Created:** [October 20, 2025, 4:13pm UTC](https://forum.ansible.com/t/use-a-variable-with-run-once/44710 "2025-10-20T16:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gazogi](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@gazogi](https://forum.ansible.com/u/gazogi)\
**Post date:** [October 20, 2025, 4:13pm UTC](https://forum.ansible.com/t/use-a-variable-with-run-once/44710/1 "2025-10-20T16:13:11Z")

</div>

I was hoping someone could help me with this. I’m trying to check the filesystem on my servers in my group to check if they have a nas mount, and then run the next task based on the results. If it is a shared file system, then I want to run the next task on only one server, other wise I want to run it on all of them. I have the following code.

- name: “Set run\_once condition based on if env is using a shared mount”  
shell: if df -l {{ hostVar\_rootDir }} \>/dev/null 2\>&1;then echo “False”;else echo “True”;fi  
register: remote\_mount  
run\_once: true

- name: Create list of tar files to clean up  
shell: ls -ltr |grep tar.gz|head -n -3|awk ‘{print $9}’  
args:  
chdir: “{{ hostVar\_rootDir }}/executor/tarfiles/”  
register: tars\_to\_remove  
run\_once: (“{{ remote\_mount.stdout }}”|bool)

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [October 20, 2025, 4:33pm UTC](https://forum.ansible.com/t/use-a-variable-with-run-once/44710/2 "2025-10-20T16:33:51Z")

</div>

bool is a Jinja filter, so it should be ‘inside’ the templating

```auto
run_once: “{{ remote_mount.stdout|bool}}"

```
