Notes
Ansible and Infrastructure Management
Many developers and system administrators manage servers by logging into them via SSH, making changes, and logging off. Some of these changes would be documented, some would not. If an admin needed to make the same change to many servers (for example, changing one value in a config file), the admin would manually log into each server and repeatedly make this change.
Tags
If you have a large playbook, it may become useful to be able to run only a specific part of it rather than running everything in the playbook.
Copy a file to a server
Retrive a file from a server
-s
: become super user-m
: use module-a
: arguments
Accelerated mode
Accelerated mode can be anywhere from 2-6x faster than SSH with ControlPersist enabled, and 10x faster than paramiko.
Async and polling
caution
Not all modules support asynchronous
Strategy
Strategy defines how a playbook is executed in ansible
- Linear strategy: Run each task across all servers in parallel at the same time. It wait for the task to finish on all servers before proceeding to the next task
Ansible notes
- Free strategy: Each server run each task independent of other severs and do not wait for the taks on other servers to finish each servers can go right to the end as fast as it can without bothering any of other servers
- Batch strategy: Ansible run tasks on three servers and when the tasks finishes, ansible run tasks on the next batch
Forks
Suppose you want to run ansible playbook on 100 hosts. Ansible will only run 5 fork at a time
You can change the forks
value as much as you like in ansible.cfg
. But make sure you have sufficient CPU resource and network bandwith for this operation
Task failure
Set value
If any tasks failed on one server. Ansible stop the execution of the play on all servers and exit
Ignore errors, failed_when
- ignore_errors: Ignore errors
- failed_when: fail on a condition