From 260bc71939f19c20c46096ef6f33c6a2afdbc11d Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 20 Nov 2022 15:09:34 +0100 Subject: [PATCH] UID and GID need user to exist first --- .../tasks/services/c-deploy/01-service-deploy.yml | 1 + playbooks/tasks/services/vars-user.yml | 15 +++++++++++++++ playbooks/tasks/services/vars.yml | 12 ------------ 3 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 playbooks/tasks/services/vars-user.yml diff --git a/playbooks/tasks/services/c-deploy/01-service-deploy.yml b/playbooks/tasks/services/c-deploy/01-service-deploy.yml index bdd5317..bb3dd3d 100644 --- a/playbooks/tasks/services/c-deploy/01-service-deploy.yml +++ b/playbooks/tasks/services/c-deploy/01-service-deploy.yml @@ -1,4 +1,5 @@ - block: - import_tasks: ../vars.yml + - import_tasks: ../vars-user.yml - import_tasks: service-deploy/service.yml tags: "{{ service_name }}" diff --git a/playbooks/tasks/services/vars-user.yml b/playbooks/tasks/services/vars-user.yml new file mode 100644 index 0000000..3aead91 --- /dev/null +++ b/playbooks/tasks/services/vars-user.yml @@ -0,0 +1,15 @@ +- name: Get user info + getent: + database: passwd + key: "{{ service_user_name }}" + +- name: Set service variables + set_fact: + service_user_uid: "{{ ansible_facts.getent_passwd[service_user_name].1 }}" + service_user_gid: "{{ ansible_facts.getent_passwd[service_user_name].2 }}" + +- name: Print service variables + debug: + msg: + - "service_user_uid: {{ service_user_uid }}" + - "service_user_gid: {{ service_user_gid }}" diff --git a/playbooks/tasks/services/vars.yml b/playbooks/tasks/services/vars.yml index 25506e9..487cc5f 100644 --- a/playbooks/tasks/services/vars.yml +++ b/playbooks/tasks/services/vars.yml @@ -10,22 +10,10 @@ set_fact: local_service_home: "./filesystem/{{ ansible_hostname }}/{{ service_home }}" -- name: Get user info - getent: - database: passwd - key: "{{ service_user_name }}" - -- name: Set service variables - set_fact: - service_user_uid: "{{ ansible_facts.getent_passwd[service_user_name].1 }}" - service_user_gid: "{{ ansible_facts.getent_passwd[service_user_name].2 }}" - - name: Print service variables debug: msg: - "service_name: {{ service_name }}" - "service_user_name: {{ service_user_name }}" - - "service_user_uid: {{ service_user_uid }}" - - "service_user_gid: {{ service_user_gid }}" - "service_home: {{ service_home }}" - "local_service_home: {{ local_service_home }}"