|
| 1 | +# Inputs: |
| 2 | +# __podman_handle_user: string - name of user |
| 3 | +# __podman_spec_item: dict - object with more information |
| 4 | +# Outputs: |
| 5 | +# ansible_facts["getent_passwd"][__podman_handle_user] |
| 6 | +# __podman_group |
| 7 | +# podman_subuid_info |
| 8 | +# podman_subgid_info |
1 | 9 | --- |
2 | 10 | - name: Get user information |
3 | 11 | getent: |
4 | 12 | database: passwd |
5 | | - key: "{{ __podman_user }}" |
| 13 | + key: "{{ __podman_handle_user }}" |
6 | 14 | fail_key: false |
7 | 15 | when: "'getent_passwd' not in ansible_facts or |
8 | | - __podman_user not in ansible_facts['getent_passwd']" |
| 16 | + __podman_handle_user not in ansible_facts['getent_passwd']" |
9 | 17 |
|
10 | 18 | - name: Fail if user does not exist |
11 | 19 | fail: |
12 | 20 | msg: > |
13 | | - The given podman user [{{ __podman_user }}] does not exist - |
| 21 | + The given podman user [{{ __podman_handle_user }}] does not exist - |
14 | 22 | cannot continue |
15 | | - when: not ansible_facts["getent_passwd"][__podman_user] |
| 23 | + when: not ansible_facts["getent_passwd"][__podman_handle_user] |
16 | 24 |
|
17 | 25 | - name: Set group for podman user |
18 | 26 | set_fact: |
|
23 | 31 | {%- elif podman_run_as_group is not none -%} |
24 | 32 | {{ podman_run_as_group }} |
25 | 33 | {%- else -%} |
26 | | - {{ ansible_facts["getent_passwd"][__podman_user][2] }} |
| 34 | + {{ ansible_facts["getent_passwd"][__podman_handle_user][2] }} |
27 | 35 | {%- endif -%} |
28 | 36 |
|
29 | 37 | - name: Check subids |
|
37 | 45 | # does not work for root |
38 | 46 | - name: Use getsubids if available |
39 | 47 | when: |
40 | | - - __podman_user not in ["root", "0"] |
| 48 | + - __podman_handle_user not in ["root", "0"] |
41 | 49 | - __podman_stat_getsubids.stat.exists |
42 | 50 | block: |
43 | 51 | - name: Check with getsubids for user subuids |
44 | | - command: getsubids {{ __podman_user | quote }} |
| 52 | + command: getsubids {{ __podman_handle_user | quote }} |
45 | 53 | changed_when: false |
46 | 54 | register: __podman_register_subuids |
47 | 55 |
|
48 | 56 | - name: Check with getsubids for user subgids |
49 | | - command: getsubids -g {{ __podman_user | quote }} |
| 57 | + command: getsubids -g {{ __podman_handle_user | quote }} |
50 | 58 | changed_when: false |
51 | 59 | register: __podman_register_subgids |
52 | 60 |
|
53 | 61 | - name: Set user subuid and subgid info |
54 | 62 | set_fact: |
55 | 63 | podman_subuid_info: "{{ podman_subuid_info | d({}) | |
56 | | - combine({__podman_user: |
| 64 | + combine({__podman_handle_user: |
57 | 65 | {'start': __subuid_data[2] | int, 'range': __subuid_data[3] | int}}) |
58 | 66 | if __subuid_data | length > 0 else podman_subuid_info | d({}) }}" |
59 | 67 | podman_subgid_info: "{{ podman_subgid_info | d({}) | |
60 | | - combine({__podman_user: |
| 68 | + combine({__podman_handle_user: |
61 | 69 | {'start': __subgid_data[2] | int, 'range': __subgid_data[3] | int}}) |
62 | 70 | if __subgid_data | length > 0 else podman_subgid_info | d({}) }}" |
63 | 71 | vars: |
|
67 | 75 | - name: Check subuid, subgid files if no getsubids |
68 | 76 | when: |
69 | 77 | - not __podman_stat_getsubids.stat.exists |
70 | | - - __podman_user not in ["root", "0"] |
| 78 | + - __podman_handle_user not in ["root", "0"] |
71 | 79 | block: |
72 | 80 | - name: Get subuid file |
73 | 81 | slurp: |
|
82 | 90 | - name: Set user subuid and subgid info |
83 | 91 | set_fact: |
84 | 92 | podman_subuid_info: "{{ podman_subuid_info | d({}) | |
85 | | - combine({__podman_user: |
| 93 | + combine({__podman_handle_user: |
86 | 94 | {'start': __subuid_data[1] | int, 'range': __subuid_data[2] | int}}) |
87 | 95 | if __subuid_data else podman_subuid_info | d({}) }}" |
88 | 96 | podman_subgid_info: "{{ podman_subgid_info | d({}) | |
89 | | - combine({__podman_user: |
| 97 | + combine({__podman_handle_user: |
90 | 98 | {'start': __subgid_data[1] | int, 'range': __subgid_data[2] | int}}) |
91 | 99 | if __subgid_data else podman_subgid_info | d({}) }}" |
92 | 100 | vars: |
93 | 101 | __subuid_match_line: "{{ |
94 | 102 | (__podman_register_subuids.content | b64decode).split('\n') | list | |
95 | | - select('match', '^' ~ __podman_user ~ ':') | list }}" |
| 103 | + select('match', '^' ~ __podman_handle_user ~ ':') | list }}" |
96 | 104 | __subuid_data: "{{ __subuid_match_line[0].split(':') | list |
97 | 105 | if __subuid_match_line else none }}" |
98 | 106 | __subgid_match_line: "{{ |
99 | 107 | (__podman_register_subgids.content | b64decode).split('\n') | list | |
100 | | - select('match', '^' ~ __podman_user ~ ':') | list }}" |
| 108 | + select('match', '^' ~ __podman_handle_user ~ ':') | list }}" |
101 | 109 | __subgid_data: "{{ __subgid_match_line[0].split(':') | list |
102 | 110 | if __subgid_match_line else none }}" |
103 | 111 |
|
104 | 112 | - name: Fail if user not in subuid file |
105 | 113 | fail: |
106 | 114 | msg: > |
107 | | - The given podman user [{{ __podman_user }}] is not in the |
| 115 | + The given podman user [{{ __podman_handle_user }}] is not in the |
108 | 116 | /etc/subuid file - cannot continue |
109 | | - when: not __podman_user in podman_subuid_info |
| 117 | + when: not __podman_handle_user in podman_subuid_info |
110 | 118 |
|
111 | 119 | - name: Fail if user not in subgid file |
112 | 120 | fail: |
113 | 121 | msg: > |
114 | | - The given podman user [{{ __podman_user }}] is not in the |
| 122 | + The given podman user [{{ __podman_handle_user }}] is not in the |
115 | 123 | /etc/subgid file - cannot continue |
116 | | - when: not __podman_user in podman_subgid_info |
| 124 | + when: not __podman_handle_user in podman_subgid_info |
0 commit comments