0
0
mirror of https://github.com/saltstack-formulas/sudoers-formula.git synced 2024-11-28 00:48:12 +01:00

Merge pull request #49 from alkivi-sas/master

feat(macro): to use in several state
This commit is contained in:
N 2021-08-18 13:38:20 +01:00 committed by GitHub
commit 933b3c9b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

22
sudoers/macros.sls Normal file
View File

@ -0,0 +1,22 @@
{%- macro sudoers(for_user, sudo, config, priority='20', state='present') -%}
{%- set filename = priority ~ '-' ~ for_user|replace('.','-') ~ '-' ~ sudo %}
{% if state == 'present' %}
/etc/sudoers.d/{{ filename }}:
file.managed:
- user: root
- group: root
- mode: 440
- template: jinja
- source: salt://sudoers/templates/sudoers.jinja
- context:
for_user: {{ for_user }}
sudo: {{ sudo }}
config: {{ config|tojson }}
{% elif state == 'absent' %}
/etc/sudoers.d/{{ filename }}:
file.absent
{% endif %}
{%- endmacro %}

View File

@ -0,0 +1,7 @@
{%- if config.command is iterable and config.command is not string -%}
{% for command in config.command -%}
{{ for_user }} {{ config.privileges }}: {{ command }}
{% endfor %}
{%- else -%}
{{ for_user }} {{ config.privileges }}: {{ config.command }}
{%- endif -%}