Skip to content

Commit

Permalink
Merge pull request #49 from alkivi-sas/master
Browse files Browse the repository at this point in the history
feat(macro): to use in several state
  • Loading branch information
noelmcloughlin authored Aug 18, 2021
2 parents dccfe9f + d8a0e12 commit 933b3c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sudoers/macros.sls
Original file line number Diff line number Diff line change
@@ -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 %}
7 changes: 7 additions & 0 deletions sudoers/templates/sudoers.jinja
Original file line number Diff line number Diff line change
@@ -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 -%}

0 comments on commit 933b3c9

Please sign in to comment.