From d321c5477db2dbd28afddf96b66ca54793ac46fc Mon Sep 17 00:00:00 2001 From: Vitaly Date: Tue, 18 Apr 2023 18:27:54 +0800 Subject: [PATCH] Remove explicit user creation check (#46) --- roles/grafana_agent/tasks/configure.yaml | 10 ++++----- .../tasks/install/user-group.yaml | 21 ++----------------- .../tasks/preflight/download.yaml | 2 +- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/roles/grafana_agent/tasks/configure.yaml b/roles/grafana_agent/tasks/configure.yaml index 6f45a8b..8e06612 100644 --- a/roles/grafana_agent/tasks/configure.yaml +++ b/roles/grafana_agent/tasks/configure.yaml @@ -18,7 +18,7 @@ - _grafana_agent_systemd_unit not in services # these tasks are ran in both install and configure, as directories could have changed -- name: Configure Directories +- name: Configure directories ansible.builtin.import_tasks: install/directories.yaml - name: Create a symbolic link @@ -29,7 +29,7 @@ group: root state: link -- name: Overwrite/Create Grafana Agent Service +- name: Overwrite/Create Grafana Agent service ansible.builtin.template: src: grafana-agent.service.j2 dest: "{{ _grafana_agent_systemd_dir }}/{{ _grafana_agent_systemd_unit }}" @@ -37,7 +37,7 @@ group: root mode: 0644 -- name: Create the Service Environment File +- name: Create the Service Environment file ansible.builtin.template: src: EnvironmentFile.j2 dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_env_file }}" @@ -45,7 +45,7 @@ group: "{{ grafana_agent_user_group }}" mode: 0640 -- name: Create Grafana Agent Config +- name: Create Grafana Agent config ansible.builtin.template: src: config.yaml.j2 dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}" @@ -55,7 +55,7 @@ mode: 0640 when: grafana_agent_provisioned_config_file | length == 0 -- name: Copy Grafana Agent Config +- name: Copy Grafana Agent config ansible.builtin.copy: src: "{{ grafana_agent_provisioned_config_file }}" dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}" diff --git a/roles/grafana_agent/tasks/install/user-group.yaml b/roles/grafana_agent/tasks/install/user-group.yaml index 0751015..7b6ba7a 100644 --- a/roles/grafana_agent/tasks/install/user-group.yaml +++ b/roles/grafana_agent/tasks/install/user-group.yaml @@ -27,29 +27,12 @@ - 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" + comment: "Grafana Agent account" groups: "{{ [ grafana_agent_user_group ] + grafana_agent_user_groups }}" 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 + when: grafana_agent_user != 'root' diff --git a/roles/grafana_agent/tasks/preflight/download.yaml b/roles/grafana_agent/tasks/preflight/download.yaml index 145eff8..ef4620a 100644 --- a/roles/grafana_agent/tasks/preflight/download.yaml +++ b/roles/grafana_agent/tasks/preflight/download.yaml @@ -17,7 +17,7 @@ ansible.builtin.set_fact: grafana_agent_version: "{{ _grafana_agent_version_request.stdout }}" - - name: Grafana Agent Version to Download + - name: Grafana Agent version to download ansible.builtin.debug: var: grafana_agent_version