Use a variable with run_once

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)

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

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