Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repo based install similar #156

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ os_supported_matrix:

## Core
nomad_debug: false
nomad_install_from_repo: false

## Asserts
nomad_skip_ensure_all_hosts: "{{ lookup('env','NOMAD_SKIP_ENSURE_ALL_HOSTS') | default('false', true) }}"
Expand Down
81 changes: 81 additions & 0 deletions tasks/install_linux_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
# File: install_linux_repo.yml - package installation tasks for Nomad

- name: Install OS packages
package:
name: "{{ item }}"
state: present
with_items: "{{ nomad_os_packages }}"
tags: installation
when: not ansible_facts['os_family'] == "VMware Photon OS"

- name: Populate service facts
service_facts:

- name: Gather the package facts
package_facts:
manager: auto

- name: Clean up previous nomad data
block:
- name: Stop service nomad, if running
service:
name: nomad
state: stopped
when: ansible_facts.services | join is match('.*nomad.*')

- name: Remove nomad service unit files from previous installation
file:
path: "{{ item }}"
state: absent
loop:
- /usr/lib/systemd/system/nomad.service
- /etc/init.d/nomad

- name: Remove the user 'nomad'
user:
name: nomad
state: absent
remove: yes

when: "'nomad' not in ansible_facts.packages"
become: true

- name: Install repository
block:
- name: Add Redhat/CentOS/Fedora/Amazon Linux repository
command: "yum-config-manager --add-repo {{ nomad_repo_url }}"
args:
creates: /etc/yum.repos.d/hashicorp.repo
when: "ansible_os_family|lower == 'redhat'"

- name: Add an Apt signing key, uses whichever key is at the URL
apt_key:
url: "{{ nomad_repo_url }}/gpg"
state: present
when: "ansible_os_family|lower == 'debian'"

- name: Add Debian/Ubuntu Linux repository
apt_repository:
repo: "deb {{ nomad_repo_url }} {{ ansible_distribution_release }} main"
state: present
update_cache: true
when: "ansible_os_family|lower == 'debian'"

when: "ansible_os_family|lower in [ 'debian', 'redhat' ]"
become: true

- name: Install nomad package
package:
name: "nomad{{ '=' if ansible_pkg_mgr == 'apt' else '-' }}{{ nomad_version }}"
state: present
become: true

- name: Remove default configuration on first install
file:
dest: "{{ nomad_config_dir }}/nomad.hcl"
state: absent
when: "'nomad' not in ansible_facts.packages"
become: true
notify:
- restart nomad
51 changes: 34 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

- name: Install OS packages
include: install.yml
when: not nomad_install_from_repo | bool

- name: Install from repo
include: install_linux_repo.yml
when: nomad_install_from_repo | bool

- name: Disable SELinux (RHEL)
include: selinux.yml
Expand Down Expand Up @@ -85,6 +90,16 @@
include_tasks: tls.yml
when: nomad_tls_enable | bool

- name: Remove default configuration
file:
dest: "{{ nomad_config_dir }}/nomad.hcl"
state: absent
when:
- nomad_allow_purge_config | bool
- nomad_install_from_repo | bool
notify:
- restart nomad

- name: Server configuration
template:
src: server.hcl.j2
Expand Down Expand Up @@ -141,7 +156,7 @@
notify:
- restart nomad

- name: Remove custome configuration
- name: Remove custom configuration
file:
dest: "{{ nomad_config_dir }}/custom.json"
state: absent
Expand Down Expand Up @@ -172,22 +187,20 @@
mode: 0755
when: not ansible_service_mgr == "systemd" and ansible_os_family == "Debian"

- name: extract systemd version
shell: |
set -o pipefail
systemctl --version systemd | head -n 1 | cut -d' ' -f2
args:
executable: /bin/bash
changed_when: false
check_mode: false
register: systemd_version
when:
- ansible_service_mgr == "systemd"
- not ansible_os_family == "FreeBSD"
- not ansible_os_family == "Solaris"
tags: skip_ansible_lint

- block:
- name: extract systemd version
shell: |
set -o pipefail
systemctl --version systemd | head -n 1 | cut -d' ' -f2
args:
executable: /bin/bash
changed_when: false
check_mode: false
register: systemd_version
when:
- not ansible_os_family == "FreeBSD"
- not ansible_os_family == "Solaris"
tags: skip_ansible_lint
- name: systemd script
template:
src: "{{ nomad_systemd_template }}"
Expand All @@ -205,7 +218,11 @@
name: nomad
enabled: yes
when: nomad_systemd_file.changed
when: ansible_service_mgr == "systemd"

when:
- ansible_service_mgr == "systemd"
# Repo install includes systemd files
- not nomad_install_from_repo

- name: Start Nomad
service:
Expand Down
2 changes: 2 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ nomad_os_packages:
{% else %}\
cgroup-tools\
{% endif %}"

nomad_repo_url: "https://apt.releases.hashicorp.com"
6 changes: 6 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ nomad_os_packages:
python3-libselinux\
{% endif %}"
- unzip

nomad_repo_url: "{% if ( ansible_distribution == 'Fedora') %}\
https://rpm.releases.hashicorp.com/fedora/hashicorp.repo\
{% else %}\
https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo\
{% endif %}"