Pavel Polushin
Pavel Polushin

Reputation: 401

How to make ansible loop over hosts sequentially

I have set of tasks that i want to execute at set of hosts sequentially.

Example is below.

hosts: all
tasks:
- name: do some work
  include_tasks: tasks_here.yml
  loop: "{{ vars[play_hosts] }}"

ansible-playbook main.yml --limit myhosts

I expect that set of tasks would be executed at first host, then at second host etc... But in fact these tasks are being executed simulatineously at all hosts in "limit". I suspect that it's happening because I use limit but i need it in my case.

So what I should I do?

Upvotes: 3

Views: 2439

Answers (1)

Alassane Ndiaye
Alassane Ndiaye

Reputation: 4767

By default, as specified here:

plays run with a linear strategy, in which all hosts will run each task before any host starts the next task.

You can use the strategy serial: 1 to execute the tasks on each host sequentially.

For example:

- hosts: all
  serial: 1
  tasks:
    ...

Upvotes: 2

Related Questions