0

I have an ansible playbook which looks roughly like this:

    - hosts: firstNode
      tasks:
      - name: create cluster
        shell: "cluster create command"

    - hosts: otherNodes
      serial: 1
      tasks:
      - name: joining cluster
        shell: "cluster join command"

firstNode is always a single host while otherNodes could be any number. It's important that each command is executed in serial. I would now like to insert a job before and after each join command to ensure that everything is working, so for a 3 node cluster the sequence would be the following jobs in serial

  1. host 1 - create cluster
  2. host 2 - check cluster status
  3. host 2 - join cluster
  4. host 2 - check node status
  5. host 3 - check cluster status
  6. host 3 - join cluster
  7. host 3 - check node status

Is this possible with ansible?

  • 2
    Just add your tasks in your second play. They will be played in order, one host at a time since your have serial=1. If needed, your can use the fail module to stop the entire playbook when something goes wrong. – Zeitounator May 14 '19 at 0:42
1

Just add your commands to the tasks block:

- hosts: firstNode
  tasks:
  - name: create cluster
    shell: "cluster create command"

- hosts: otherNodes
  serial: 1
  tasks:
  - name: check cluster
    shell: "check cluster command"

  - name: joining cluster
    shell: "cluster join command"

  - name: check node
    shell: "check node command"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.