add thanos role

This commit is contained in:
2022-08-30 07:51:26 -05:00
parent 04dfdbd399
commit 4c64613a90
14 changed files with 483 additions and 0 deletions

View File

@ -0,0 +1,15 @@
---
- name: "{{ item }}: configure systemd"
template:
src: "{{ item }}.service.j2"
dest: "/etc/systemd/system/{{ item }}.service"
owner: root
group: root
mode: 0444
notify: "restart {{ item | replace('-', ' ')}}"
- name: "{{ item }}: manage service"
service:
name: "{{ item }}.service"
enabled: "{{ lookup('vars', item | replace('-', '_') + '_service_enabled') }}"
state: "{{ lookup('vars', item | replace('-', '_') + '_service_state') }}"

View File

@ -0,0 +1,63 @@
---
- name: sysctl fs.protected_hardlinks
sysctl:
name: fs.protected_hardlinks
value: "0"
sysctl_set: yes
state: present
- name: create group
group:
name: "{{ thanos_group }}"
system: true
state: "{{ thanos_group_state | default('present') }}"
- name: create user
user:
name: "{{ thanos_user }}"
system: true
shell: "{{ thanos_user_shell }}"
group: "{{ thanos_group }}"
groups: "{{ prometheus_group }}"
createhome: false
home: "{{ thanos_var_path }}"
state: "{{ thanos_user_state | default('present') }}"
append: true
- name: create etc path
file:
path: "{{ thanos_etc_path }}"
state: directory
owner: "{{ thanos_etc_owner }}"
group: "{{ thanos_etc_group }}"
mode: "{{ thanos_etc_mode }}"
- name: create var path
file:
path: "{{ thanos_var_path }}"
state: directory
owner: "{{ thanos_var_owner }}"
group: "{{ thanos_var_group }}"
mode: "{{ thanos_var_mode }}"
- name: configure bucket
copy:
dest: "{{ thanos_sidecar_objstore_config_file }}"
content: "{{ (thanos_bucket_config | default({})) | to_nice_yaml }}"
owner: "{{ thanos_sidecar_objstore_config_file_owner }}"
group: "{{ thanos_sidecar_objstore_config_file_group }}"
mode: "{{ thanos_sidecar_objstore_config_file_mode }}"
notify: restart thanos sidecar
- name: configure thanos query frontend cache
copy:
dest: "{{ thanos_etc_path }}/cache.yaml"
content: "{{ (thanos_query_frontend_cache_config | default({})) | to_nice_yaml }}"
owner: "{{ thanos_user }}"
group: "{{ thanos_group }}"
mode: "0444"
notify: restart thanos query frontend
- name: configure thanos components
include: configure-component.yaml
loop: "{{ thanos_services }}"

View File

View File

@ -0,0 +1,30 @@
---
- block:
- name: download tar
get_url:
url: "{{ thanos_release_url }}"
dest: "{{ thanos_download_path }}"
checksum: "{{ thanos_checksum }}"
register: dl
until: dl is success
retries: 5
delay: 10
- name: extract tar
unarchive:
src: "{{ thanos_download_path }}"
dest: "{{ thanos_unarchive_dest_path }}"
creates: "{{ thanos_extracted_path }}"
remote_src: true
- name: install binaries
copy:
src: "{{ thanos_extracted_path }}/{{ item }}"
dest: "{{ thanos_bin_path }}/{{ item }}"
owner: root
group: root
mode: 0755
remote_src: true
loop: "{{ thanos_binaries }}"
notify: restart thanos
when: thanos_version != thanos_local_version

View File

@ -0,0 +1,30 @@
---
- name: gather os specific variables
include_vars: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- vars
- name: include os specific tasks
include_tasks: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- tasks
- include: pre.yaml
- include: install.yaml
- include: configure.yaml

View File

@ -0,0 +1,54 @@
---
- name: determine if installed
stat:
path: "{{ thanos_bin_path }}/thanos"
register: st
- name: set thanos_installed
set_fact:
thanos_installed: "{{ st.stat.exists | bool }}"
- block:
- name: determine latest version
uri:
url: "https://api.github.com/repos/{{ thanos_github_rel_path }}/releases/latest"
return_content: true
body_format: json
register: _latest_version
until: _latest_version.status == 200
retries: 3
- name: set thanos_version
set_fact:
thanos_version: "{{ _latest_version.json['tag_name'] | regex_replace('^v', '') }}"
- block:
- name: determine installed version
command: "{{ thanos_bin_path }}/thanos --version"
register: _installed_version_string
changed_when: false
- name: set thanos_local_version
set_fact:
thanos_local_version: "{{ _installed_version_string.stdout | regex_search(thanos_version_regex, '\\1') | first }}"
rescue:
- name: set thanos_local_version
set_fact:
thanos_local_version: "{{ _installed_version_string.stderr | regex_search(thanos_version_regex, '\\1') | first }}"
when: thanos_installed
- name: set thanos_local_version to 0
set_fact:
thanos_local_version: "0"
when: not thanos_installed
- block:
- name: get checksums
set_fact:
_checksums: "{{ lookup('url', thanos_checksum_url, wantlist=True) }}"
- name: set thanos_checksum
set_fact:
thanos_checksum: "{{ thanos_checksum_algo }}:{{ item.split(' ') | first }}"
loop: "{{ _checksums }}"
when: "thanos_release_file in item"