-
Notifications
You must be signed in to change notification settings - Fork 26
/
07_nomad-demo-jobs.yml
86 lines (77 loc) · 3.1 KB
/
07_nomad-demo-jobs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
- name: "HashiCorp - Nomad - Jobs : Demo Jobs."
hosts: all
become: true
vars_files:
- vars/general/main.yml
- vars/hashicorp/general.yml
- vars/hashicorp/nomad.yml
- vars/hashicorp/demo.yml
- vars/hashicorp/ssl.yml
tasks:
- name: "HashiCorp - Nomad - Jobs : Retrieve Operator Secret ID."
ansible.builtin.shell: "awk '/Secret ID/ {print $4}' {{ nomad_operator_token_local_path }}"
changed_when: false
become: false
delegate_to: localhost
run_once: true
register: nomad_operator_token
- name: "HashiCorp - Nomad - Jobs : Register the Node ID from the first client for constraints demo."
ansible.builtin.shell: "{{ nomad_binary }} node status -self -short | grep ID -m1 | awk '{print $3}'"
environment:
NOMAD_TOKEN: "{{ nomad_operator_token.stdout }}"
changed_when: false
register: nomad_first_client_node_id
delegate_to: "{{ groups['clients'] | first }}"
run_once: true
- name: "HashiCorp - Nomad - Jobs : Ensure FQDN in first server."
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: "{{ hostvars[item].ansible_host }} {{ demo_fqdn }}"
line: "{{ hostvars[item].ansible_host }} {{ demo_fqdn }}"
delegate_to: "{{ groups['servers'] | first }}"
with_items: "{{ groups.clients | first }}"
run_once: true
tags: demo-fqdn
- name: "HashiCorp - Nomad - Jobs : Deployment."
block:
- name: "HashiCorp - Nomad - Jobs : Ensure job directory is present on the first server."
become: true
ansible.builtin.file:
path: "{{ nomad_demo_job_remote_location }}"
state: directory
recurse: true
- name: "HashiCorp - Nomad - Jobs : Ensure job directory is present on this client."
become: true
ansible.builtin.file:
path: "{{ nomad_demo_job_local_location }}"
state: directory
mode: "0777"
delegate_to: localhost
- name: "HashiCorp - Nomad - Jobs : Ensure demo jobs are templated and in place."
ansible.builtin.template:
src: "{{ item.template }}"
dest: "{{ item.destination }}"
mode: "0666"
with_items: "{{ nomad_demo_job_names }}"
when: nomad_first_client_node_id is defined
- name: "HashiCorp - Nomad : Retrieve job content."
ansible.builtin.fetch:
src: "{{ item.destination }}"
dest: "{{ nomad_demo_job_local_location }}/"
flat: yes
with_items: "{{ nomad_demo_job_names }}"
- name: "HashiCorp - Nomad : Ensure demo jobs are running."
community.general.nomad_job:
host: localhost
use_ssl: false
state: present
token: "{{ nomad_operator_token.stdout }}"
content: "{{ lookup('file', item.destination) }}"
timeout: 60
force_start: true
with_items: "{{ nomad_demo_job_names }}"
when:
- ansible_hostname in groups['servers']
delegate_to: "{{ groups['servers'] | first }}"
run_once: true