-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow resetting UID/GID of the aegir user on ansible play runs. * Kill all tasks running of the user and chown everything to the new UID. * Separate user create and UID reset plays #610
- Loading branch information
Showing
6 changed files
with
103 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
- name: Detect current Aegir user UID | ||
getent: | ||
database: passwd | ||
key: "{{ aegir_user_name }}" | ||
failed_when: false | ||
|
||
- name: Detect current Aegir user GID | ||
getent: | ||
database: group | ||
key: "{{ aegir_user_name }}" | ||
failed_when: false | ||
|
||
- name: Save variables for current user UID and GID | ||
set_fact: | ||
aegir_user_uid_current: "{{ getent_passwd[aegir_user_name][1] }}" | ||
aegir_user_gid_current: "{{ getent_group[aegir_user_name][1] }}" | ||
when: | ||
- getent_passwd is defined | ||
|
||
- name: Current Aegir User UID & GID | ||
debug: | ||
msg: "UID: {{ aegir_user_uid_current }} GID: {{ aegir_user_gid_current }}" | ||
when: | ||
- getent_passwd is defined | ||
|
||
- name: Desired Aegir User UID & GID | ||
debug: | ||
msg: "UID: {{ aegir_user_uid }} GID: {{ aegir_user_gid }}" | ||
when: | ||
- getent_passwd is defined | ||
|
||
- name: Include Reset Aegir User tasks | ||
include_tasks: "reset-uid.yml" | ||
when: | ||
(aegir_user_uid != aegir_user_uid_current) | ||
or (aegir_user_gid != aegir_user_gid_current) | ||
or (aegir_user_force_set_uid) | ||
tags: [always] | ||
|
||
- name: Create Aegir Group (so we can set the GID) | ||
group: | ||
name: "{{ aegir_user_name }}" | ||
state: present | ||
gid: "{{ aegir_user_gid }}" | ||
|
||
- name: Populate service facts | ||
service_facts: | ||
|
||
- name: Create Aegir user | ||
when: | ||
- aegir_create_user | ||
user: | ||
name: "{{ aegir_user_name }}" | ||
shell: /bin/bash | ||
group: "{{ aegir_user_name }}" | ||
system: true | ||
home: "{{ aegir_user_home }}" | ||
generate_ssh_key: true | ||
uid: "{{ aegir_user_uid }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
|
||
- name: "User ID Change: Stop supervisord" | ||
service: | ||
name: supervisord | ||
state: stopped | ||
|
||
- name: "User ID Change: Find all user processes" | ||
shell: "ps -ef | grep -v grep | grep -w {{ aegir_user_name }} | awk '{print $2}'" | ||
register: running_processes | ||
|
||
- name: Aegir User Processes | ||
debug: | ||
var: running_processes | ||
|
||
- name: "User ID Change: Kill all user processes" | ||
command: "kill {{ item }}" | ||
ignore_errors: true | ||
with_items: "{{ running_processes.stdout_lines }}" | ||
|
||
- name: "User ID Change: Wait for all processes to end" | ||
wait_for: | ||
path: "/proc/{{ item }}/status" | ||
state: absent | ||
with_items: "{{ running_processes.stdout_lines }}" | ||
ignore_errors: true | ||
register: killed_processes | ||
|
||
- name: "User ID Change: Force stop stuck processes" | ||
command: "kill -9 {{ item }}" | ||
with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}" |