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 %}
|
2014-05-30 05:20:13 +02:00
|
|
|
|
2014-05-31 13:14:00 +02:00
|
|
|
# Ensure availability of bash
|
2015-07-27 19:45:56 +02:00
|
|
|
users-bashpackage-group-dir:
|
2014-05-31 13:14:00 +02:00
|
|
|
pkg.installed:
|
2015-07-27 19:45:56 +02:00
|
|
|
- name: {{ users_settings.bash_package }}
|
2014-05-31 13:14:00 +02:00
|
|
|
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 }}
|
2014-05-31 13:14:00 +02:00
|
|
|
|
2015-07-27 19:45:56 +02:00
|
|
|
users-sudo-package:
|
2014-05-31 13:14:00 +02:00
|
|
|
pkg.installed:
|
2015-07-27 19:45:56 +02:00
|
|
|
- name: {{ users_settings.sudo_package }}
|
2013-06-19 21:53:46 +02:00
|
|
|
- require:
|
2015-05-07 00:07:06 +02:00
|
|
|
- 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 %}
|