Interview Prep/Ansible/Rapid-Fire Commands

How do you run a long command in the background on many hosts and check it later?

IntermediateProductionRapid-Fire Commands
Answer
ansible db -b -B 7200 -P 0 -m ansible.builtin.command -a "/opt/scripts/backup.sh"
# returns an ansible_job_id per host, e.g. j123456789.4242
ansible db -b -m ansible.builtin.async_status -a "jid=j123456789.4242"

-B is the maximum runtime in seconds, -P 0 means fire and forget. Use the same become user when checking status, because job files live in that user's home.

All Ansible questions Roadmap: Ansible

More on Rapid-Fire Commands