---
- name: Install or update nomad
  become: true
  apt:
    name: nomad
    state: latest
    update_cache: yes
  when: ansible_check_mode == false

- name: Add nomad user
  become: true
  user:
    name: nomad
    shell: /bin/false
    system: yes

- name: Create nomad group
  become: true
  group:
    name: nomad
    system: yes

- name: Create nomad directories
  become: true
  file:
    path: '{{ item }}'
    state: directory
    owner: nomad
    group: nomad
    mode: 0750
  with_items:
    - /etc/nomad.d
    - /opt/nomad

- include_tasks: configure.yml

- name: Enable and start nomad
  become: true
  systemd:
    name: nomad
    enabled: yes
    state: started
  when: ansible_check_mode == false