0
0
mirror of https://github.com/saltstack-formulas/users-formula.git synced 2024-11-27 22:38:34 +01:00
users-formula/users/sudo.sls

90 lines
2.8 KiB
Plaintext
Raw Normal View History

2015-07-27 19:45:56 +02:00
# -*- coding: utf-8 -*-
# vim: ft=sls
{##
Name: users/sudo.sls
Description:
This file sets up sudoers
#}
{% from "users/map.jinja" import users_settings with context %}
# Ensure availability of bash
2015-07-27 19:45:56 +02:00
users-bashpackage-group-dir:
pkg.installed:
2015-07-27 19:45:56 +02:00
- name: {{ users_settings.bash_package }}
group.present:
- name: sudo
2013-06-19 21:53:46 +02:00
- system: True
2015-07-27 19:45:56 +02:00
file.directory:
- name: {{ users_settings.sudoers_dir }}
2015-07-27 19:45:56 +02:00
users-sudo-package:
pkg.installed:
2015-07-27 19:45:56 +02:00
- name: {{ users_settings.sudo_package }}
2013-06-19 21:53:46 +02:00
- require:
- group: users_sudo-group
2015-07-27 19:45:56 +02:00
- file: {{ users_settings.sudoers_dir }}
file.append:
- name: {{ users_settings.sudoers_file }}
- text:
- Defaults env_reset
- Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- '#includedir {{ users_settings.sudoers_dir }}'
{% for name, user in users_settings.items() %}
{% if user.absent is not defined or not user.absent or user != None %}
{% if 'sudouser' in user and user['sudouser'] %}
users-sudoer-{{ name }}:
file.managed:
- name: {{ users.sudoers_dir }}/{{ name }}
- user: root
- group: {{ users.root_group }}
- mode: '0440'
{% if 'sudo_rules' in user or 'sudo_defaults' in user %}
{% if 'sudo_rules' in user %}
{% for rule in user['sudo_rules'] %}
"validate {{ name }} sudo rule {{ loop.index0 }} {{ name }} {{ rule }}":
cmd.run:
- name: 'visudo -cf - <<<"$rule" | { read output; if [[ $output != "stdin: parsed OK" ]] ; then echo $output ; fi }'
- stateful: True
- shell: {{ users.visudo_shell }}
- env:
# Specify the rule via an env var to avoid shell quoting issues.
- rule: "{{ name }} {{ rule }}"
{% endfor %}
{% endif %}
{% if 'sudo_defaults' in user %}
{% for entry in user['sudo_defaults'] %}
"validate {{ name }} sudo Defaults {{ loop.index0 }} {{ name }} {{ entry }}":
cmd.run:
- name: 'visudo -cf - <<<"$rule" | { read output; if [[ $output != "stdin: parsed OK" ]] ; then echo $output ; fi }'
- stateful: True
- shell: {{ users.visudo_shell }}
- env:
# Specify the rule via an env var to avoid shell quoting issues.
- rule: "Defaults:{{ name }} {{ entry }}"
{% endfor %}
{% endif %}
2013-06-19 21:53:46 +02:00
2015-07-27 19:45:56 +02:00
users_{{ users.sudoers_dir }}/{{ name }}:
file.managed:
- name: {{ users.sudoers_dir }}/{{ name }}
- contents: |
{%- if 'sudo_defaults' in user %}
{%- for entry in user['sudo_defaults'] %}
Defaults:{{ name }} {{ entry }}
{%- endfor %}
{%- endif %}
{%- if 'sudo_rules' in user %}
{%- for rule in user['sudo_rules'] %}
{{ name }} {{ rule }}
{%- endfor %}
{%- endif %}
{% endif %}
{% else %}
users_{{ users.sudoers_dir }}/{{ name }}:
file.absent:
- name: {{ users.sudoers_dir }}/{{ name }}
{% endif %}
{% endif %}
{% endfor %}