0
votes

I have a list of hosts and roles to apply on each. They are hosted on a hypvervisor (XenServer / ESX).

I'm trying to revert each machine back to snapshot before executing the ansible plays. My flow of actions looks like this:

  1. Take VM name from a file (machines.txt)
  2. Connect the Hypervisor and through CLI revert the machine snapshot
  3. Once SSH is up for the machine, connect and execute rest of the plays
  4. Execute one machine at a time.

The best I came so far is executing the revert task on the hypervisor in one play, and then a different play to apply the roles. So that's how my playbook looks like:

---
  - name: Reverting
    hosts: xenhost
    tasks:
      - include_tasks: tasks/vms/revert_snap.yml
        with_lines: cat "machines.txt"

  - name: Ensure NTP is installed
    hosts: temp
    roles:
      - ntp

The solution I've found so far is,

  1. Execute a task of reverting snapshot from CLI and execute it on the Hypervisor
  2. Execute my whole maintenance play on the machines 2.1 Wait for SSH on each 2.2 Apply roles

  3. Clean up and take new snapshots on the Hypervisor

The drawback I have in this scenario is, first it reverts ALL machines, then apply all the roles and then reverting all of them in bulk. I can't combine the tasks into a single play because they are executed on different hosts.

Any better solutions? - which will revert one machine, apply all roles, take snapshot, then continue to the next machine.

1

1 Answers

0
votes

Any better solutions? - which will revert one machine, apply all roles, take snapshot, then continue to the next machine.

you could group all those tasks in a role, and execute the role with serial: 1

- hosts: hostgroup
  serial: 1
  roles:
    - {role: rolename }