---
- name: Add Hashistack group
  group:
    name: "{{ hashistack_group }}"
    state: present

- name: Add Hashistack users
  user:
    name: "{{ item }}"
    group: "{{ hashistack_group }}"
    system: true
    create_home: false
  with_items:
    - "{{ consul_user }}"
    - "{{ nomad_user }}"

- block:
  - name: Add 'monitoring' group
    group:
      name: "{{ monitoring_group }}"
      gid: "{{ monitoring_gid }}"
      state: present

  - name: Add 'monitoring' user
    user:
      name: "{{ monitoring_user }}"
      uid: "{{ monitoring_uid }}"
      group: "{{ monitoring_group }}"
  when: layerops_instance_type == "orchestrator"

- name: Add 'layerops' group
  group:
    name: "{{ layerops_group }}"
    state: present

- name: Add 'layerops' user
  user:
    name: "{{ layerops_user }}"
    shell: "{{ layerops_user_shell }}"
    home: "{{ layerops_home_dir }}"
    group: "{{ layerops_group }}"

- name: Allow 'layerops' group to have passwordless sudo
  template:
    src: sudoers.conf
    dest: "{{ layerops_sudoers_config_file }}"
