-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresolve_user.yml
More file actions
32 lines (28 loc) · 942 Bytes
/
resolve_user.yml
File metadata and controls
32 lines (28 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
---
- name: resolve remote user facts
block:
- name: Determine local user
ansible.builtin.set_fact:
local_user: >-
{{ ansible_env.SUDO_USER
| default(ansible_user_id)
| default(ansible_ssh_user) }}
- name: Determine home_dir
ansible.builtin.shell: "echo ~{{ local_user }}"
changed_when: false
register: _home_dir_result
- name: Get primary group on remote host
ansible.builtin.command: "id -gn {{ local_user }}"
changed_when: false
register: _primary_group_result
- name: Set derived facts
ansible.builtin.set_fact:
home_dir: "{{ _home_dir_result.stdout }}"
local_user_primary_group: "{{ _primary_group_result.stdout }}"
- name: Display resolved facts
ansible.builtin.debug:
msg:
local_user: "{{ local_user }}"
home_dir: "{{ home_dir }}"
local_user_primary_group: "{{ local_user_primary_group }}"
tags: always