mirror of
https://github.com/saltstack-formulas/sudoers-formula.git
synced 2024-11-27 22:38:22 +01:00
feat(macro): to use in several state
This commit is contained in:
parent
00480b992c
commit
70e66c97be
22
sudoers/macros.sls
Normal file
22
sudoers/macros.sls
Normal 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 }}
|
||||||
|
|
||||||
|
{% elif state == 'absent' %}
|
||||||
|
/etc/sudoers.d/{{ filename }}:
|
||||||
|
file.absent
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{%- endmacro %}
|
7
sudoers/templates/sudoers.jinja
Normal file
7
sudoers/templates/sudoers.jinja
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{%- if config.command is string -%}
|
||||||
|
{{ for_user }} {{ config.privileges }}: {{ config.command }}
|
||||||
|
{%- else -%}
|
||||||
|
{% for command in config.command -%}
|
||||||
|
{{ for_user }} {{ config.privileges }}: {{ command }}
|
||||||
|
{% endfor %}
|
||||||
|
{%- endif -%}
|
Loading…
Reference in New Issue
Block a user