Ansible - How to sequentially execute playbook for each host

AnsibleAnsible Playbook

Ansible Problem Overview


I am using ansible to script a deployment for an API. I would like this to work sequentially through each host in my inventory file so that I can fully deploy to one machine at a time.

With the out box behaviour, each task in my playbook is executed for each host in the inventory file before moving on to the next task.

How can I change this behaviour to execute all tasks for a host before starting on the next host? Ideally I would like to only have one playbook.

Thanks

Ansible Solutions


Solution 1 - Ansible

Have a closer look at Rolling Updates:

What you are searching for is

- hosts: webservers
  serial: 1
  tasks:
    - name: ...

Solution 2 - Ansible

Using the --forks=1 specify number of parallel processes to use (default=5)

Solution 3 - Ansible

Strategy enable to parallel tasks in a per host basis. See https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html

There are 3 strategies: linear (the default), serial and free (quickest)

- hosts: all
  strategy: free
  tasks:
    ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLynnView Question on Stackoverflow
Solution 1 - AnsibleProfHase85View Answer on Stackoverflow
Solution 2 - AnsibleJobin JamesView Answer on Stackoverflow
Solution 3 - AnsibleMUY BelgiumView Answer on Stackoverflow