How do you collect a file such as a log from many hosts at once?
BeginnerProductionRapid-Fire Commands
Answer
ansible web -b -m ansible.builtin.fetch -a "src=/var/log/nginx/error.log dest=./logs/"
# result: ./logs/web01/var/log/nginx/error.log, ./logs/web02/...
fetch stores each host's file under its own directory, so files never overwrite each other. Use flat=yes only for a single host, and compress large logs on the target first.
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