feat(postgres_exporter): add ansible role for deployment using docker
This commit is contained in:
parent
e173fab4e9
commit
bcc788497f
35
roles/postgres_exporter/defaults/main.yml
Normal file
35
roles/postgres_exporter/defaults/main.yml
Normal file
@ -0,0 +1,35 @@
|
||||
---
|
||||
|
||||
postgres_exporter_version: "0.10.1"
|
||||
postgres_exporter_user: root
|
||||
postgres_exporter_create_user: false
|
||||
|
||||
postgres_exporter_db_host: ~
|
||||
postgres_exporter_db_user: postgres
|
||||
postgres_exporter_db_pass: ~
|
||||
postgres_exporter_db_port: ~
|
||||
postgres_exporter_db_sslmode: false
|
||||
|
||||
postgres_exporter_container_name: postgres_exporter
|
||||
postgres_exporter_container_image_name: quay.io/prometheuscommunity/postgres-exporter
|
||||
postgres_exporter_container_image_tag: ~
|
||||
postgres_exporter_container_image_ref: "{{ postgres_exporter_container_image_name }}:{{ postgres_exporter_container_image_tag | default('v' + postgres_exporter_version) }}"
|
||||
postgres_exporter_container_networks: ~
|
||||
postgres_exporter_container_purge_networks: false
|
||||
postgres_exporter_container_volumes: []
|
||||
postgres_exporter_container_ports: ~
|
||||
postgres_exporter_container_env:
|
||||
DATA_SOURCE_NAME: >-
|
||||
user={{ postgres_exporter_db_user }}
|
||||
host={{ postgres_exporter_db_host }}
|
||||
sslmode={{ 'enable' if postgres_exporter_db_sslmode else 'disable' }}
|
||||
{% if postgres_exporter_db_pass %}
|
||||
pass={{ postgres_exporter_db_pass }}
|
||||
{% endif %}
|
||||
{% if postgres_exporter_db_port %}
|
||||
port={{ postgres_exporter_db_port }}
|
||||
{% endif %}
|
||||
postgres_exporter_container_labels:
|
||||
VERSION: "{{ postgres_exporter_version }}"
|
||||
postgres_exporter_container_user: "{{ postgres_exporter_user_info.uid if postgres_exporter_user_info is defined else postgres_exporter_user }}"
|
||||
postgres_exporter_container_restart_policy: unless-stopped
|
30
roles/postgres_exporter/tasks/main.yml
Normal file
30
roles/postgres_exporter/tasks/main.yml
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
|
||||
- name: Ensure user '{{ postgres_exporter_user }}' exists
|
||||
user:
|
||||
name: "{{ postgres_exporter_user }}"
|
||||
state: present
|
||||
system: yes
|
||||
register: postgres_exporter_user_info
|
||||
when: postgres_exporter_create_user
|
||||
|
||||
- name: Ensure container image '{{ postgres_exporter_container_image_ref }}' is available
|
||||
community.docker.docker_container_image:
|
||||
name: "{{ postgres_exporter_container_image_ref }}"
|
||||
state: present
|
||||
source: pull
|
||||
force_source: "{{ postgres_exporter_container_image_tag|bool }}"
|
||||
|
||||
- name: Ensure postgres exporter container '{{ postgres_exporter_container_name }}' is running
|
||||
docker_container:
|
||||
name: "{{ postgres_exporter_container_name }}"
|
||||
image: "{{ postgres_exporter_container_image_ref }}"
|
||||
networks: "{{ postgres_exporter_container_networks | default(omit) }}"
|
||||
purge_networks: "{{ postgres_exporter_container_purge_networks }}"
|
||||
volumes: "{{ postgres_exporter_container_volumes | default(omit) }}"
|
||||
labels: "{{ postgres_exporter_container_labels | default(omit) }}"
|
||||
ports: "{{ postgres_exporter_container_ports | default(omit) }}"
|
||||
user: "{{ postgres_exporter_container_user }}"
|
||||
env: "{{ postgres_exporter_container_env }}"
|
||||
restart_policy: "{{ postgres_exporter_container_restart_policy }}"
|
||||
state: started
|
Loading…
Reference in New Issue
Block a user