Add initial sudo role

This commit is contained in:
Ryan Cavicchioni 2019-11-22 21:09:18 -06:00
parent 885a37ee0a
commit 8a31ccb6ac
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
3 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,21 @@
---
sudo_package_name: sudo
sudo_package_state: present
sudo_includedir: /etc/sudoers.d
sudo_default_rules:
- name: root
hosts: ALL
runas:
users: ALL
groups: ALL
commands: ALL
sudo_aliases: {}
sudo_rules: []
sudo_rules_raw: []
sudo_defaults:
- env_reset
- mail_badpass
- secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

View File

@ -0,0 +1,14 @@
---
- name: install
package:
name: "{{ sudo_package_name }}"
state: "{{ sudo_package_state }}"
- name: configure
template:
src: "sudoers.j2"
dest: /etc/sudoers
owner: root
group: root
mode: 0440
validate: visudo -cf %s

View File

@ -0,0 +1,62 @@
{%- macro render_list(v) -%}
{% if v is string -%}
{{ v }}
{%- elif v is sequence %}
{{ v | join(', ') }}
{%- endif %}
{%- endmacro -%}
{%- macro render_tags(v) -%}
{% if v is defined and v is sequence and v | length -%}
{{ render_list(v) }}:
{%- endif %}
{%- endmacro -%}
{%- macro render_runas(v) -%}
{% if v is string -%}
{{ v }}
{%- elif v is mapping %}
{% if "users" in v -%}
{{ render_list(v["users"]) }}
{%- endif -%}
{% if "groups" in v %}
:{{ render_list(v["groups"]) }}
{%- endif %}
{%- endif %}
{%- endmacro -%}
# {{ ansible_managed }}
{% if sudo_aliases is defined and sudo_aliases is mapping -%}
{% for type, aliases in sudo_aliases | dictsort %}
{% for alias in aliases | sort(attribute='name') %}
{{ type | capitalize }}_Alias {{ alias.name | upper }} = {{ render_list(alias["items"]) }}
{% endfor %}
{% endfor %}
{%- endif %}
{% if sudo_defaults is defined and sudo_defaults is sequence and sudo_defaults | length -%}
# Defaults
{% for default in sudo_defaults %}
Defaults {{ default }}
{% endfor %}
{%- endif %}
{% for rule in sudo_default_rules %}
{{ render_list(rule.name) }} {{ render_list(rule.hosts | default("ALL")) }} = ({{ render_runas(rule.runas | default("ALL")) }}) {{ render_tags(rule.tags) }} {{ render_list(rules.commands | default("ALL")) }}
{% endfor %}
{% for rule in sudo_rules %}
{{ render_list(rule.name) }} {{ render_list(rule.hosts | default("ALL")) }} = ({{ render_runas(rule.runas | default("ALL")) }}) {{ render_tags(rule.tags) }} {{ render_list(rules.commands | default("ALL")) }}
{% endfor %}
{%- if sudo_rules_raw is defined and sudo_rules_raw is sequence and sudo_rules_raw | length -%}
# Raw rules
{% for rule in sudo_rules_raw %}
{{ rule }}
{% endfor %}
{%- endif %}
{% if sudo_includedir is defined %}
#includedir {{ sudo_includedir }}
{% endif %}