---

- name: Start and enable nomad service
  service: name=nomad state=started enabled=True
  register: nomad_service_started
  tags: nomad

- name: Handle consul-template-nomad service
  service:
    name: consul-template-nomad
    state: "{{ (nomad_vault_secrets.pki.enabled or nomad_vault_secrets.consul_pki.enabled or nomad_vault_secrets.tokens.enabled) | ternary('started', 'stopped') }}"
    enabled: "{{ (nomad_vault_secrets.pki.enabled or nomad_vault_secrets.consul_pki.enabled or nomad_vault_secrets.tokens.enabled) | ternary(True, False) }}"
  tags: nomad

- name: Handle iptables-nomad-cleanup service
  service:
    name: iptables-nomad-cleanup
    enabled: "{{ (nomad_conf.client.enabled and iptables_manage | default(True)) | ternary(True, False) }}"
  tags: nomad
