Skip to content

Commit

Permalink
Merge pull request #45 from Dmitriusan/fix_wrong_user_home_dir
Browse files Browse the repository at this point in the history
fix wrong user home dir for .kube directory
  • Loading branch information
istvano authored Jan 14, 2024
2 parents bccaf93 + 8fcca41 commit ab622f3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tasks/configure-groups.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# add user specific settings
---

# Fetch home directories of users https://stackoverflow.com/a/48892377
- user:
name: '{{ user }}'
state: present
register: user_info
with_items: '{{ users }}'
loop_control:
loop_var: user
label: '{{ user }}'

- name: Transform user_homes into a dictionary
set_fact:
user_info_dict: "{{ user_info_dict | default({}) | combine({item['user']: item}) }}"
with_items: "{{ user_info.results }}"

- name: add user to group
become: yes
command: "usermod -a -G microk8s {{ user }}"
Expand All @@ -13,7 +29,7 @@
become: yes
become_user: '{{ user }}'
file:
path: ~/.kube
path: "{{ user_info_dict[user]['home'] }}/.kube"
state: directory
owner: '{{ user }}'
group: '{{ user }}'
Expand All @@ -26,7 +42,7 @@
- name: create kubectl config
become: yes
changed_when: true
shell: microk8s config > /home/{{ user }}/.kube/config
shell: microk8s config > {{ user_info_dict[user]['home'] }}/.kube/config
args:
executable: /bin/bash
with_items: '{{ users }}'
Expand All @@ -37,7 +53,7 @@
- name: reaffirm permission on files
become: yes
file:
path: ~/.kube
path: "{{ user_info_dict[user]['home'] }}/.kube"
state: directory
owner: '{{ user }}'
group: '{{ user }}'
Expand Down

0 comments on commit ab622f3

Please sign in to comment.