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.
More on Rapid-Fire Commands
How do you see which hosts a playbook would run against, without running it?BeginnerHow do you list the tasks and tags a playbook contains?BeginnerHow do you inspect the inventory structure and a host's variables?BeginnerHow do you restart a service on a group with an ad-hoc command?BeginnerHow do you resume a playbook from a specific task or step through it?BeginnerHow do you re-run a playbook only on the hosts that failed?Intermediate