Search code examples
ansibleansible-role

Serial execution of a role in Ansible


I have a playbook defined as below:

- name: install percona rpms
  hosts: imdp
  roles:
    - role1
    - role2
    - role3
    - role4

I just want the tasks defined in role 3 to be executed serially. If I define serial: 1 in the role3 tasks, it doesn't work. All tasks are executed in parallel. But if I defined serial: 1 in the main yaml (the above yaml) then all the roles are executed serially, which is also not needed.

How can I get just role3 to be executed serially?


Solution

  • "serial" is available in a play only. See Playbook Keywords. The solution is to split the roles among more plays. For example

    - name: Play 1. install percona rpms
      hosts: imdp
      roles:
        - role1
        - role2
    
    - name: Play 2. install percona rpms
      hosts: imdp
      serial: 1
      roles:
        - role3
    
    - name: Play 3. install percona rpms
      hosts: imdp
      roles:
        - role4