ansible-nas/roles/nomad/tasks/main.yml
2023-02-05 23:26:12 +00:00

54 lines
1.3 KiB
YAML

---
- name: Install and start Nomad
block:
- name: Add Hashicorp GPG key
ansible.builtin.apt_key:
url: https://apt.releases.hashicorp.com/gpg
state: present
- name: Add Hashicorp apt repository
ansible.builtin.apt_repository:
repo: "deb https://apt.releases.hashicorp.com {{ ansible_facts['lsb']['codename'] }} main"
state: present
filename: hashicorp
- name: Install Nomad
ansible.builtin.apt:
name: nomad
state: present
- name: Template Nomad config
ansible.builtin.template:
src: nomad.hcl
dest: /etc/nomad.d/nomad.hcl
notify: restart nomad
- name: Start Nomad
ansible.builtin.systemd:
name: "{{ nomad_service_name }}"
state: started
enabled: yes
when: nomad_enabled is true
- name: Stop Nomad
block:
- name: Check if Nomad is installed
stat:
path: /usr/bin/nomad
register: nomad_install
- block:
- name: Stop Nomad
ansible.builtin.systemd:
name: "{{ nomad_service_name }}"
state: stopped
enabled: no
daemon_reload: yes
- name: Uninstall Nomad
ansible.builtin.apt:
name: nomad
state: absent
when: nomad_install.stat.exists
when: nomad_enabled is false