grafana-ansible-collection/roles/grafana_agent/tasks/install/user-group.yaml
2023-03-03 14:23:02 +05:30

57 lines
2.1 KiB
YAML

---
- name: Grafana Agent Group Creation
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'
- name: Grafana Agent User Group Exists
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
- name: Grafana Agent User Creation
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'
- name: Grafana Agent User Exists
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