From 0119db15e83588cfd40d086ec2809f368d858905 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Wed, 4 Jan 2023 07:52:21 +0100 Subject: [PATCH] Properly fix daemon reload --- .../roles/services/include/meta/argument_specs.yml | 2 +- .../roles/services/include/tasks/daemon_reload.yml | 2 +- .../services/include/tasks/daemon_reload/main.yml | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/playbooks/roles/services/include/meta/argument_specs.yml b/playbooks/roles/services/include/meta/argument_specs.yml index b00da3a..002c71d 100644 --- a/playbooks/roles/services/include/meta/argument_specs.yml +++ b/playbooks/roles/services/include/meta/argument_specs.yml @@ -3,6 +3,6 @@ argument_specs: daemon_reload: options: services_host_services: - type: "list" + type: "dict" elem: "dict" required: true diff --git a/playbooks/roles/services/include/tasks/daemon_reload.yml b/playbooks/roles/services/include/tasks/daemon_reload.yml index c5a581b..62dff95 100644 --- a/playbooks/roles/services/include/tasks/daemon_reload.yml +++ b/playbooks/roles/services/include/tasks/daemon_reload.yml @@ -1,6 +1,6 @@ --- - name: "daemon_reload : loop over services" ansible.builtin.include_tasks: "daemon_reload/main.yml" - loop: "{{ services_host_services | dict2items | selectattr('key') }}" + loop: "{{ services_host_services | dict2items | map(attribute='key') }}" loop_control: loop_var: "services_service_name" diff --git a/playbooks/roles/services/include/tasks/daemon_reload/main.yml b/playbooks/roles/services/include/tasks/daemon_reload/main.yml index 5e0da49..5551c2e 100644 --- a/playbooks/roles/services/include/tasks/daemon_reload/main.yml +++ b/playbooks/roles/services/include/tasks/daemon_reload/main.yml @@ -1,11 +1,12 @@ --- - name: "daemon_reload : {{ services_service_name }} : set variables" - ansible.builtin.import_tasks: "../vars.yml" + ansible.builtin.include_vars: "user.yml" -- name: "daemon_reload : {{ services_service_name }} : check if home exists" - ansible.builtin.stat: - path: "{{ services_service_user_home }}" - register: services_include_daemon_reload_user_home +- name: "daemon_reload : {{ services_service_name }} : check if user exists" + ansible.builtin.getent: + database: "passwd" + key: "{{ services_service_user_name }}" + fail_key: false - name: "daemon_reload : {{ services_service_name }} : systemd daemon reload" become_user: "{{ services_service_user_name }}" @@ -13,4 +14,4 @@ daemon_reload: true scope: "user" when: - services_include_daemon_reload_user_home.stat.exists + ansible_facts.getent_passwd[services_service_user_name]