Senior
How to make Ansible execute a playbook sequentially on one host at a time (for updating a Postgres cluster)?
sobes.tech AI
Answer from AI
To make Ansible execute a playbook sequentially on one host at a time, you need to use the serial parameter with a value of 1 in the playbook. This will force Ansible to process hosts one by one, which is useful for updating a cluster to avoid updating all nodes simultaneously.
Example:
- hosts: postgres_cluster
serial: 1
tasks:
- name: Update Postgres
yum:
name: postgresql
state: latest
You can also use --forks=1 when running ansible-playbook to limit the number of parallel processes to one.
ansible-playbook playbook.yml --forks=1