Files
ansible-homelab/roles/nomad/tasks/main.yml
T
2026-02-04 10:00:21 -06:00

132 lines
2.9 KiB
YAML

---
- name: Install dependencies
apt:
name:
- curl
- gnupg
- lsb-release
- qemu-system-x86
- qemu-utils
state: present
update_cache: yes
when: nomad_driver_qemu
- name: Ensure HashiCorp GPG key is present
apt_key:
url: https://apt.releases.hashicorp.com/gpg
state: present
- name: Ensure HashiCorp repository is present
apt_repository:
repo: "deb [arch=amd64] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main"
state: present
filename: hashicorp
- name: Install Nomad
apt:
name: "nomad={{ nomad_version }}-1"
state: present
update_cache: yes
- name: Create Nomad data directory
file:
path: "{{ nomad_data_dir }}"
state: directory
owner: root
group: root
mode: '0755'
- name: Create Nomad config directory
file:
path: "{{ nomad_config_dir }}"
state: directory
owner: root
group: root
mode: '0755'
- name: Create CNI plugins directory
file:
path: /opt/cni/bin
state: directory
mode: '0755'
- name: Download CNI plugins
unarchive:
src: "https://github.com/containernetworking/plugins/releases/download/v{{ nomad_cni_version }}/cni-plugins-linux-amd64-v{{ nomad_cni_version }}.tgz"
dest: /opt/cni/bin
remote_src: yes
creates: /opt/cni/bin/bridge
- name: Configure bridge networking for CNI
copy:
dest: /etc/sysctl.d/99-nomad-bridge.conf
content: |
net.bridge.bridge-nf-call-arptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
mode: '0644'
notify: Reload sysctl
- name: Load br_netfilter module
modprobe:
name: br_netfilter
state: present
- name: Ensure br_netfilter loads on boot
copy:
dest: /etc/modules-load.d/br_netfilter.conf
content: "br_netfilter"
mode: '0644'
- name: Deploy Nomad base configuration
template:
src: nomad.hcl.j2
dest: "{{ nomad_config_dir }}/nomad.hcl"
owner: root
group: root
mode: '0640'
notify: Restart Nomad
- name: Deploy server configuration
template:
src: server.hcl.j2
dest: "{{ nomad_config_dir }}/server.hcl"
owner: root
group: root
mode: '0640'
when: nomad_server
notify: Restart Nomad
- name: Remove server config on non-servers
file:
path: "{{ nomad_config_dir }}/server.hcl"
state: absent
when: not nomad_server
- name: Deploy client configuration
template:
src: client.hcl.j2
dest: "{{ nomad_config_dir }}/client.hcl"
owner: root
group: root
mode: '0640'
when: nomad_client
notify: Restart Nomad
- name: Enable and start Nomad service
systemd:
name: nomad
enabled: yes
state: started
daemon_reload: yes
- name: Wait for Nomad to be ready
uri:
url: "http://127.0.0.1:4646/v1/status/leader"
method: GET
register: nomad_leader
until: nomad_leader.status == 200
retries: 30
delay: 2
when: nomad_server