2023-03-03 09:53:02 +01:00
|
|
|
---
|
2023-03-10 06:45:00 +01:00
|
|
|
- name: Grafana Agent group creation
|
2023-03-03 09:53:02 +01:00
|
|
|
block:
|
|
|
|
- name: "Check if the group exists ({{ grafana_agent_user_group }})"
|
|
|
|
ansible.builtin.getent:
|
|
|
|
database: group
|
|
|
|
key: "{{ grafana_agent_user_group }}"
|
|
|
|
fail_key: false
|
|
|
|
|
|
|
|
- name: Set whether not the user group exists
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
__grafana_agent_user_group_exists: "{{ ansible_facts.getent_group[grafana_agent_user_group] is not none }}"
|
|
|
|
|
|
|
|
- name: Add user group "{{ grafana_agent_user_group }}"
|
|
|
|
ansible.builtin.group:
|
|
|
|
name: "{{ grafana_agent_user_group }}"
|
|
|
|
system: true
|
|
|
|
state: present
|
|
|
|
when: not __grafana_agent_user_group_exists and grafana_agent_user_group != 'root'
|
|
|
|
|
2023-03-10 06:45:00 +01:00
|
|
|
- name: Grafana Agent user group exists
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: |-
|
|
|
|
The user group \"{{ grafana_agent_user_group }}\" already exists and will not be modified,
|
|
|
|
if modifying permissions please perform a separate task
|
|
|
|
when: __grafana_agent_user_group_exists
|
|
|
|
|
2023-03-10 06:45:00 +01:00
|
|
|
- name: Grafana Agent user creation
|
2023-03-03 09:53:02 +01:00
|
|
|
block:
|
|
|
|
- name: "Check if the user exists ({{ grafana_agent_user }})"
|
|
|
|
ansible.builtin.getent:
|
|
|
|
database: passwd
|
|
|
|
key: "{{ grafana_agent_user }}"
|
|
|
|
fail_key: false
|
|
|
|
|
|
|
|
- name: Set whether not the user exists
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
__grafana_agent_user_exists: "{{ ansible_facts.getent_passwd[grafana_agent_user] is not none }}"
|
|
|
|
|
|
|
|
- name: Add user "{{ grafana_agent_user }}"
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ grafana_agent_user }}"
|
|
|
|
comment: "Grafana Agent Account"
|
|
|
|
groups:
|
|
|
|
- "{{ grafana_agent_user_group }}"
|
|
|
|
system: true
|
|
|
|
shell: "{{ grafana_agent_user_shell }}"
|
|
|
|
createhome: "{{ grafana_agent_user_createhome }}"
|
|
|
|
when: not __grafana_agent_user_exists and grafana_agent_user != 'root'
|
|
|
|
|
2023-03-10 06:45:00 +01:00
|
|
|
- name: Grafana Agent user exists
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: |-
|
|
|
|
The user \"{{ grafana_agent_user }}\" already exists and will not be modified,
|
|
|
|
if modifying permissions please perform a separate task
|
|
|
|
when: __grafana_agent_user_exists
|