Browse Source

perf(users/init.sls): don't create groups multiple times

pull/223/head
Stanislav Asunkin 3 years ago
parent
commit
987a451599
1 changed files with 23 additions and 12 deletions
  1. +23
    -12
      users/init.sls

+ 23
- 12
users/init.sls View File

{% set used_user_files = [] %} {% set used_user_files = [] %}
{% set used_polkit = [] %} {% set used_polkit = [] %}
{%- set create_dirs = [] %} {%- set create_dirs = [] %}
{%- set created_groups = [] %}


{% for group, setting in salt['pillar.get']('groups', {}).items() %} {% for group, setting in salt['pillar.get']('groups', {}).items() %}
{% if setting.absent is defined and setting.absent or setting.get('state', "present") == 'absent' %} {% if setting.absent is defined and setting.absent or setting.get('state', "present") == 'absent' %}
group.absent: group.absent:
- name: {{ group }} - name: {{ group }}
{% else %} {% else %}
{%- do created_groups.append(group) %}
users_group_present_{{ group }}: users_group_present_{{ group }}:
group.present: group.present:
- name: {{ group }} - name: {{ group }}
{%- endif %} {%- endif %}


{%- if not ( 'sudoonly' in user and user['sudoonly'] ) %} {%- if not ( 'sudoonly' in user and user['sudoonly'] ) %}
{% for group in user.get('groups', []) %}
users_{{ name }}_{{ group }}_group:

{#- create prime group #}
{%- if user_group not in created_groups %}
{%- do created_groups.append(user_group) %}
users_group_present_{{ user_group }}:
group.present:
- name: {{ user_group }}
{%- if 'prime_group' in user and 'gid' in user['prime_group'] %}
- gid: {{ user['prime_group']['gid'] }}
{%- elif 'uid' in user %}
- gid: {{ user['uid'] }}
{%- endif %}
{% if 'system' in user and user['system'] %}
- system: True
{% endif %}
{%- endif %}

{#- create required groups #}
{%- for group in user.get('groups', []) if group not in created_groups %}
{%- do created_groups.append(group) %}
users_group_present_{{ group }}:
group.present: group.present:
- name: {{ group }} - name: {{ group }}
{% if group == 'sudo' %} {% if group == 'sudo' %}
- user: users_{{ name }}_user - user: users_{{ name }}_user
- group: {{ user_group }} - group: {{ user_group }}
{%- endif %} {%- endif %}
group.present:
- name: {{ user_group }}
{%- if 'prime_group' in user and 'gid' in user['prime_group'] %}
- gid: {{ user['prime_group']['gid'] }}
{%- elif 'uid' in user %}
- gid: {{ user['uid'] }}
{%- endif %}
{% if 'system' in user and user['system'] %}
- system: True
{% endif %}
user.present: user.present:
- name: {{ name }} - name: {{ name }}
- home: {{ home }} - home: {{ home }}

Loading…
Cancel
Save