Run ansible tasks on hosts one-by-one

Here is my question exactlyt the same.

https://stackoverflow.com/questions/64048208/run-ansible-tasks-on-hosts-one-by-one

Run 3 tasks one after another on single host at at a time.
if any of that tasks fails dont move ahead.

Now when i use throttle with block it runs tasks on both the hosts.

Serial does not work with block at at all.

serial is a PLAY level keyword and what you want to use in this case,
throttle will only control the forks/parallel jobs, not serialize a
batch (this is what serial does).

How to acheive this then ??

Put the tasks in a play, you can have multiple plays per playbook

- name: One host at a time
  hosts: ducks_in_a_row
  serial: 1
  max_fail_percentage: 0
  tasks:
    - task1
    - task2
    - task3

so what i tried is , I created another playbook and inside that mentioned serial which works fine with add_host . I am getting expected results but when i tried to add this code in my actual role. (I first test code in temporary playbook , so that i dont mess the role)

But when copy paste the code in my role here obviously structure is different,
main.yml–>zookeeper.yml(task yaml )–> imported playbook(new playbook as serial only works for plays).

code ,

this is zookeeper.yml which is a task list yaml, and not a playbook

  • name: Check who is existing zokeeper leader

shell: ‘echo stat | nc localhost “{{hostvars[inventory_hostname].zk_port}}” | grep Mode’

register: zkmode

  • name: Set service name as a fact

set_fact:

service_name: “{{ zookeeper_service_name }}”

  • name: Restart playbook

import_playbook: Restart.yml

now when i run the role i get

ERROR! this task ‘import_playbook’ has extra params, which is only allowed in the following modules: command, include, ansible.legacy.meta, ansible.legacy.set_fact, import_tasks, ansible.legacy.import_role, win_shell, group_by, win_command, ansible.builtin.set_fact, include_vars, ansible.builtin.shell, ansible.builtin.meta, ansible.legacy.group_by, ansible.legacy.win_command, set_fact, import_role, ansible.legacy.command, ansible.legacy.include_tasks, ansible.builtin.import_role, ansible.legacy.raw, meta, include_role, ansible.legacy.win_shell, include_tasks, ansible.builtin.script, add_host, ansible.legacy.add_host, ansible.builtin.include_tasks, script, ansible.builtin.include_vars, ansible.windows.win_command, ansible.builtin.add_host, ansible.legacy.include, ansible.legacy.include_role, ansible.legacy.shell, ansible.builtin.include_role, shell, ansible.legacy.script, ansible.builtin.win_shell, ansible.builtin.win_command, ansible.builtin.command, ansible.builtin.raw, raw, ansible.legacy.import_tasks, ansible.legacy.include_vars, ansible.builtin.group_by, ansible.windows.win_shell, ansible.builtin.include, ansible.builtin.import_tasks

The error appears to be in ‘/Users/sameer_modak/ansibledemo/prometheus/tasks/zookeeper_prometheus.yml’: line 118, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • name: Imporing Restartandcheck yaml

^ here

roles can be in plays, plays cannot be in roles

how should place these playbooks and what should be the order. Below is my role .

https://github.com/sameergithub5/prometheusrole

Pllaybooks can contain plays, plays can contain tasks, blocks and
roles, but you cannot reverse the direction of 'containers'.

You CANNOT have a play in a role, so your question is a non starter.
You have to write a playbook with multiple plays.

ok i heard you. Let met try