---

- name: Create the archive dir
  file: path={{ nomad_root_dir }}/archives/{{ nomad_current_version }} state=directory
  tags: nomad

- name: Snapshot nomad data
  command: "{{ nomad_root_dir }}/bin/nomad operator snapshot save {{ nomad_root_dir }}/archives/{{ nomad_current_version }}/nomad.snap"
  args:
    creates: "{{ nomad_root_dir }}/archives/{{ nomad_current_version }}/nomad.snap"
  environment:
    NOMAD_TOKEN: "{{ nomad_mgm_token | default(omit) }}"
  tags: nomad

- name: Backup previous version
  synchronize:
    src: "{{ nomad_root_dir }}/{{ item }}"
    dest: "{{ nomad_root_dir }}/archives/{{ nomad_current_version }}/"
    compress: False
  delegate_to: "{{ inventory_hostname }}"
  loop:
    - bin
    - plugins
  tags: nomad

