---
- name: Nomad installed
  community.general.pkgng:
    name: "nomad,py38-six"
    state: latest
  tags:
    - dc1
    - dc2

- name: Nomad enabled
  shell: sysrc nomad_enable="YES"
  tags:
    - dc1
    - dc2
  notify: Nomad restarted

- name: Nomad debug set
  shell: sysrc nomad_debug="YES"
  tags:
    - dc1
    - dc2
  notify: Nomad restarted

- name: Nomad user configured
  shell: sysrc nomad_user="root"
  tags:
    - dc1
    - dc2
  notify: Nomad restarted

- name: Nomad dc1 configured
  shell: sysrc nomad_args="-config /usr/local/etc/nomad -network-interface epair0b -dc dc1"
  tags:
    - dc1
  notify: Nomad restarted

- name: Nomad dc2 configured
  shell: sysrc nomad_args="-config /usr/local/etc/nomad -network-interface epair0b -dc dc2"
  tags:
    - dc2
  notify: Nomad restarted

- name: Nomad server.hcl removed
  file:
    state: absent
    dest: /usr/local/etc/nomad/server.hcl
  tags:
    - dc1
    - dc2
  notify: Nomad restarted

- name: Nomad client.hcl installed
  copy:
    src: client.hcl
    dest: /usr/local/etc/nomad/client.hcl
    owner: root
    mode: 0644
  tags:
    - dc1
    - dc2
  notify: Nomad restarted

- name: http-echo copied
  copy:
    src: http-echo
    dest: /usr/local/bin/http-echo
    owner: root
    mode: a+x
  tags:
    - dc1
    - dc2

- name: Nomad dns setup
  template:
    src: dnsmasq.conf.j2
    dest: /usr/local/etc/dnsmasq.conf
    owner: root
    mode: 0644
  tags:
    - dc1
    - dc2
  notify: Dnsmasq restarted

- name: Nomad started
  service: name=nomad state=started
  tags:
    - dc1
    - dc2
