Broke apart the playbook into roles.

This commit is contained in:
2023-07-14 12:57:35 +05:30
parent 7744dd0520
commit 3bbacab487
13 changed files with 285 additions and 241 deletions

View File

@ -0,0 +1,6 @@
---
# Default variables for InfluxDB role
influx_user: "{{ ansible_user }}"
influx_image: "influxdb:latest"
influx_directory: "/var/lib/influxtestroledir"
influx_container: "influxtestrole"

View File

@ -0,0 +1,50 @@
---
# Tasks for InfluxDB role
- getent:
database: passwd
key: "{{ influx_user }}"
split: ":"
- name: Pull InfluxDB image
docker_image:
name: "{{ influx_image }}"
source: pull
force_source: yes
- name: Ensure Influx Directory exists
file:
path: "{{ influx_directory }}"
state: directory
group: "{{ influx_user }}"
owner: "{{ influx_user }}"
mode: 0755
- name: Ensure Influx Data Directory exists
file:
path: "{{ influx_directory }}/data"
state: directory
group: "{{ influx_user }}"
owner: "{{ influx_user }}"
mode: 0755
- name: Ensure Influx Config Directory exists
file:
path: "{{ influx_directory }}/config"
state: directory
group: "{{ influx_user }}"
owner: "{{ influx_user }}"
mode: 0755
- name: Create InfluxDB container
docker_container:
name: "{{ influx_container }}"
image: "{{ influx_image }}"
state: started
restart_policy: "unless-stopped"
user: "{{ getent_passwd[influx_user][1] }}:{{ getent_passwd[influx_user][2] }}"
published_ports:
- 127.0.0.1:8088:8086
volumes:
- "{{ influx_directory }}/data:/var/lib/influxdb2"
- "{{ influx_directory }}/config:/etc/influxdb2"