Last active
July 25, 2018 22:08
-
-
Save lopcode/9233a86c453dbe88ff47507c04390e88 to your computer and use it in GitHub Desktop.
Simple Nomad installation and updating using Ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To update to a new version of Nomad: | |
# Download and calculate checksums: | |
# http --download https://releases.hashicorp.com/nomad/0.8.4/nomad_0.8.4_linux_amd64.zip | |
# shasum --algorithm 256 --binary nomad_0.8.4_linux_amd64.zip | |
# unzip nomad_0.8.4_linux_amd64.zip | |
# shasum --algorithm 256 --binary nomad | |
# Update facts in this script | |
# Only run on one hashimaster at a time! | |
- name: Set nomad version | |
set_fact: | |
nomad_version: "0.8.4" | |
- name: Set nomad variables | |
set_fact: | |
nomad_url: "https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_linux_amd64.zip" | |
nomad_checksum: "238bd6da77e0a7e46ae710d6a12719514a9be252c45f9aebe424305954f24169" | |
nomad_zip_checksum: "42fc455d09ea0085cc79d7be4fb2089a9ab7db3cc2e8047e8437855a81b090e9" | |
- name: Make Nomad folders | |
file: | |
path: "{{ item }}" | |
state: directory | |
owner: "{{ user }}" | |
group: "{{ user }}" | |
mode: 0775 | |
with_items: ["{{ ansible_env.HOME }}/.nomad", "/etc/nomad", "/var/lib/nomad"] | |
- name: Check for existence of Nomad and get stats | |
stat: | |
path: /usr/bin/nomad | |
checksum_algorithm: "sha256" | |
register: existing_file | |
- name: Check if Nomad checksum matches | |
set_fact: | |
nomad_version_mismatch: "{{ existing_file.stat.checksum is not defined or (existing_file.stat.checksum != nomad_checksum) }}" | |
- name: Download Nomad | |
get_url: | |
url: "{{ nomad_url }}" | |
dest: "{{ ansible_env.HOME }}/.nomad" | |
checksum: "sha256:{{ nomad_zip_checksum }}" | |
when: nomad_version_mismatch | |
- name: Install unzip | |
apt: | |
name: "{{ item }}" | |
state: present | |
with_items: ["unzip"] | |
when: nomad_version_mismatch | |
- name: Unzip Nomad | |
unarchive: | |
src: "{{ ansible_env.HOME }}/.nomad/nomad_{{ nomad_version }}_linux_amd64.zip" | |
dest: "{{ ansible_env.HOME }}/.nomad/" | |
copy: no | |
when: nomad_version_mismatch | |
- name: Copy Nomad to /usr/bin | |
command: "cp {{ ansible_env.HOME }}/.nomad/nomad /usr/bin/nomad" | |
when: nomad_version_mismatch | |
- name: Template Nomad server configuration | |
template: | |
src: server.hcl | |
dest: /etc/nomad/server.hcl | |
owner: "{{ user }}" | |
group: "{{ user }}" | |
mode: 0775 | |
- name: Copy systemd configuration | |
copy: | |
src: nomad.service | |
dest: /etc/systemd/system/nomad.service | |
owner: "{{ user }}" | |
group: "{{ user }}" | |
mode: 0775 | |
- name: Restart nomad systemd service | |
service: | |
name: "{{ item }}" | |
state: restarted | |
with_items: ["nomad"] | |
when: nomad_version_mismatch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Nomad | |
Documentation=https://nomadproject.io/docs/ | |
[Service] | |
KillMode=process | |
KillSignal=SIGINT | |
ExecStart=/usr/bin/nomad agent -config /etc/nomad | |
ExecReload=/bin/kill -HUP $MAINPID | |
LimitNOFILE=65536 | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bind_addr = "{{ ansible_eth1.ipv4.address }}" | |
data_dir = "/var/lib/nomad" | |
datacenter = "your_datacenter" | |
addresses { | |
http = "0.0.0.0" | |
} | |
server { | |
enabled = true | |
bootstrap_expect = {{ nomad_host_count }} | |
server_join { | |
retry_join = ["provider=your_provider region=lon1 tag_name=nomad_server api_token={{ lookup('env','YOUR_TOKEN') }}"] | |
} | |
} | |
consul { | |
address = "127.0.0.1:8500" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment