Browse Source

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

pull/223/head
Stanislav Asunkin 3 years ago
parent
commit
0c4b1ad4ad
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      users/init.sls

+ 17
- 10
users/init.sls View File

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


{% 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' %}
{%- set user_group = name -%} {%- set user_group = name -%}
{%- endif %} {%- endif %}


{%- if createhome %}
{%- set required_dir = salt['file.dirname'](home) %}
{%- do create_dirs.append(required_dir) %}
{%- endif %}

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


{# in case home subfolder doesn't exist, create it before the user exists #}
{% if createhome -%}
users_{{ name }}_user_prereq:
file.directory:
- name: {{ salt['file.dirname'](home) }}
- makedirs: True
- prereq:
- user: users_{{ name }}_user
{%- endif %}

users_{{ name }}_user: users_{{ name }}_user:
{% if createhome -%} {% if createhome -%}
file.directory: file.directory:
{% for group in user.get('groups', []) -%} {% for group in user.get('groups', []) -%}
- group: {{ group }} - group: {{ group }}
{% endfor %} {% endfor %}
{%- if createhome and required_dir != '/' %}
- file: users_prereq_dir_{{ required_dir }}
{%- endif %}




{% if 'ssh_keys' in user or {% if 'ssh_keys' in user or


{% endfor %} {% endfor %}


{#- create directories for homes #}
{%- for dir in create_dirs|unique|reject('equalto', '/') %}
users_prereq_dir_{{ dir }}:
file.directory:
- name: {{ dir }}
- makedirs: True
{%- endfor %}



{% for name, user in pillar.get('users', {}).items() {% for name, user in pillar.get('users', {}).items()
if user.absent is defined and user.absent %} if user.absent is defined and user.absent %}

Loading…
Cancel
Save