Skip to content

Commit b3d2e19

Browse files
committed
Add install from repo rather than bins
1 parent a0f567e commit b3d2e19

File tree

5 files changed

+135
-24
lines changed

5 files changed

+135
-24
lines changed

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ os_supported_matrix:
3030

3131
## Core
3232
nomad_debug: false
33+
nomad_install_from_repo: false
3334

3435
## Asserts
3536
nomad_skip_ensure_all_hosts: "{{ lookup('env', 'NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }}"

tasks/install_linux_repo.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
# File: install_linux_repo.yml - package installation tasks for Nomad
3+
4+
- name: Install OS packages
5+
ansible.builtin.package:
6+
name: "{{ item }}"
7+
state: present
8+
with_items: "{{ nomad_os_packages }}"
9+
tags: installation
10+
when: not ansible_facts['os_family'] == "VMware Photon OS"
11+
12+
- name: Populate service facts
13+
ansible.builtin.service_facts:
14+
15+
- name: Gather the package facts
16+
ansible.builtin.package_facts:
17+
manager: auto
18+
19+
- name: Clean up previous nomad data
20+
block:
21+
- name: Stop service nomad, if running
22+
ansible.builtin.service:
23+
name: nomad
24+
state: stopped
25+
when: ansible_facts.services | join is match('.*nomad.*')
26+
27+
- name: Remove nomad service unit files from previous installation
28+
ansible.builtin.file:
29+
path: "{{ item }}"
30+
state: absent
31+
loop:
32+
- /usr/lib/systemd/system/nomad.service
33+
- /etc/init.d/nomad
34+
35+
- name: Remove the user 'nomad'
36+
ansible.builtin.user:
37+
name: nomad
38+
state: absent
39+
remove: yes
40+
41+
when: "'nomad' not in ansible_facts.packages"
42+
become: true
43+
44+
- name: Install repository
45+
block:
46+
- name: Add Redhat/CentOS/Fedora/Amazon Linux repository
47+
ansible.builtin.command: "yum-config-manager --add-repo {{ nomad_repo_url }}"
48+
args:
49+
creates: /etc/yum.repos.d/hashicorp.repo
50+
when: "ansible_os_family|lower == 'redhat'"
51+
52+
- name: Add an Apt signing key, uses whichever key is at the URL
53+
ansible.builtin.apt_key:
54+
url: "{{ nomad_repo_url }}/gpg"
55+
state: present
56+
when: "ansible_os_family|lower == 'debian'"
57+
58+
- name: Add Debian/Ubuntu Linux repository
59+
ansible.builtin.apt_repository:
60+
repo: "deb {{ nomad_repo_url }} {{ ansible_distribution_release }} main"
61+
state: present
62+
update_cache: true
63+
when: "ansible_os_family|lower == 'debian'"
64+
65+
when: "ansible_os_family|lower in [ 'debian', 'redhat' ]"
66+
become: true
67+
68+
- name: Install nomad package
69+
ansible.builtin.package:
70+
name: "nomad{{ '=' if ansible_pkg_mgr == 'apt' else '-' }}{{ nomad_version }}"
71+
state: present
72+
become: true
73+
74+
- name: Remove default configuration on first install
75+
ansible.builtin.file:
76+
dest: "{{ nomad_config_dir }}/nomad.hcl"
77+
state: absent
78+
when: "'nomad' not in ansible_facts.packages"
79+
become: true
80+
notify:
81+
- Restart nomad

tasks/main.yml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
- name: Install OS packages
3838
ansible.builtin.include_tasks:
3939
file: install.yml
40+
when: not nomad_install_from_repo | bool
41+
42+
- name: Install from repo
43+
ansible.builtin.include_tasks:
44+
file: install_linux_repo.yml
45+
when: nomad_install_from_repo | bool
4046

4147
- name: Disable SELinux (RHEL)
4248
ansible.builtin.include_tasks:
@@ -95,6 +101,16 @@
95101
file: tls.yml
96102
when: nomad_tls_enable | bool
97103

104+
- name: Remove default configuration
105+
file:
106+
dest: "{{ nomad_config_dir }}/nomad.hcl"
107+
state: absent
108+
when:
109+
- nomad_allow_purge_config | bool
110+
- nomad_install_from_repo | bool
111+
notify:
112+
- restart nomad
113+
98114
- name: Server configuration
99115
ansible.builtin.template:
100116
src: server.hcl.j2
@@ -151,7 +167,7 @@
151167
notify:
152168
- Restart nomad
153169

154-
- name: Remove custome configuration
170+
- name: Remove custom configuration
155171
ansible.builtin.file:
156172
dest: "{{ nomad_config_dir }}/custom.json"
157173
state: absent
@@ -183,31 +199,37 @@
183199
mode: "0755"
184200
when: not ansible_service_mgr == "systemd" and ansible_os_family == "Debian"
185201

186-
- name: Extract systemd version
187-
ansible.builtin.shell:
188-
cmd: set -o pipefail && systemctl --version systemd | head -n 1 | cut -d ' ' -f2
189-
args:
190-
executable: /bin/bash
191-
changed_when: false
192-
check_mode: false
193-
register: systemd_version
202+
- block:
203+
- name: Extract systemd version
204+
ansible.builtin.shell:
205+
cmd: set -o pipefail && systemctl --version systemd | head -n 1 | cut -d ' ' -f2
206+
args:
207+
executable: /bin/bash
208+
changed_when: false
209+
check_mode: false
210+
register: systemd_version
211+
when:
212+
- ansible_service_mgr == "systemd"
213+
- not ansible_os_family == "FreeBSD"
214+
- not ansible_os_family == "Solaris"
215+
tags: skip_ansible_lint
216+
217+
- name: Create systemd unit
218+
ansible.builtin.template:
219+
src: "{{ nomad_systemd_template }}"
220+
dest: "{{ nomad_systemd_unit_path }}/nomad.service"
221+
owner: root
222+
group: root
223+
mode: "0644"
224+
notify:
225+
- Reload systemd daemon
226+
- Enable nomad at startup (systemd)
227+
when: ansible_service_mgr == "systemd"
228+
194229
when:
195230
- ansible_service_mgr == "systemd"
196-
- not ansible_os_family == "FreeBSD"
197-
- not ansible_os_family == "Solaris"
198-
tags: skip_ansible_lint
199-
200-
- name: Create systemd unit
201-
ansible.builtin.template:
202-
src: "{{ nomad_systemd_template }}"
203-
dest: "{{ nomad_systemd_unit_path }}/nomad.service"
204-
owner: root
205-
group: root
206-
mode: "0644"
207-
notify:
208-
- Reload systemd daemon
209-
- Enable nomad at startup (systemd)
210-
when: ansible_service_mgr == "systemd"
231+
# Repo install includes systemd files
232+
- not nomad_install_from_repo
211233

212234
- name: Start Nomad
213235
ansible.builtin.service:

vars/Debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ nomad_os_packages:
99
- unzip
1010
- "{% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('19', '<')) or (ansible_distribution == 'Debian' and ansible_distribution_version
1111
is version('11', '<')) %}cgroup-bin{% else %}cgroup-tools{% endif %}"
12+
nomad_repo_url: "https://apt.releases.hashicorp.com"

vars/RedHat.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ nomad_os_packages:
88
is version('8', '<')) or (ansible_distribution == 'Amazon' and ansible_distribution_version is version('3', '<')) or (ansible_distribution == 'OracleLinux' and
99
ansible_distribution_version is version('8', '<')) %}libselinux-python{% else %}python3-libselinux{% endif %}"
1010
- unzip
11+
12+
nomad_repo_url: "{% if ( ansible_distribution == 'Fedora') %}\
13+
https://rpm.releases.hashicorp.com/fedora/hashicorp.repo\
14+
{% else %}\
15+
https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo\
16+
{% endif %}"

0 commit comments

Comments
 (0)