Skip to content

Commit 044a3de

Browse files
committed
Add install from repo rather than bins
1 parent 92d4e33 commit 044a3de

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

defaults/main.yml

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

2727
## Core
2828
nomad_debug: false
29+
nomad_install_from_repo: false
2930

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

tasks/install_linux_repo.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
# File: install_linux_repo.yml - package installation tasks for Nomad
3+
4+
- name: Install OS packages
5+
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+
service_facts:
14+
15+
- name: Gather the package facts
16+
package_facts:
17+
manager: auto
18+
19+
- name: Clean up previous nomad data
20+
block:
21+
- name: Stop service nomad, if running
22+
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+
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+
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+
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+
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+
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+
package:
70+
name: "nomad{{ '=' if ansible_pkg_mgr == 'apt' else '-' }}{{ consul_version }}"
71+
state: present
72+
become: true

tasks/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
- name: Install OS packages
3535
include: install.yml
36+
when: not nomad_install_from_repo | bool
37+
38+
- name: Install from repo
39+
include: install_linux_repo.yml
40+
when: nomad_install_from_repo | bool
3641

3742
- name: Disable SELinux (RHEL)
3843
include: selinux.yml

vars/Debian.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ nomad_os_packages:
1313
{% else %}\
1414
cgroup-tools\
1515
{% endif %}"
16+
17+
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
@@ -14,3 +14,9 @@ nomad_os_packages:
1414
python3-libselinux\
1515
{% endif %}"
1616
- unzip
17+
18+
nomad_repo_url: "{% if ( ansible_distribution == 'Fedora') %}\
19+
https://rpm.releases.hashicorp.com/fedora/hashicorp.repo\
20+
{% else %}\
21+
https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo\
22+
{% endif %}"

0 commit comments

Comments
 (0)