Add role users

This commit is contained in:
Tobias Hachmer 2018-02-28 06:03:28 +01:00
parent be84e6f148
commit 3c8d012ac7
17 changed files with 112 additions and 63 deletions

View file

@ -7,6 +7,7 @@
- prerequisites - prerequisites
- server-apt-repos - server-apt-repos
- server-basic - server-basic
- users
- system-sysctl-gateway - system-sysctl-gateway
- git-repos - git-repos
- service-haveged - service-haveged

View file

@ -1,7 +0,0 @@
---
dependencies:
- { role: ffmwu-prereqs }
- { role: packages, server_pkg_repo_list: "{{meshing_pkg_repo_list}}",
server_pkg_pkg_list: "{{meshing_pkg_pkg_list}}",
server_pkg_pip_list: "{{meshing_pkg_pip_list}}",
really_do: "{{ansible_managed_server}}" }

View file

@ -1,25 +0,0 @@
---
# we don't want to disrupt servers where this role is manually maintained!
# thus: warning and block statement
- name: full-stop if server role is manually maintained on this server
debug: msg="server role skipped to not disrupt manual maintenance - set ansible_managed_server to True to enable ansible control"
when: (not ansible_managed_server is defined) or (not ansible_managed_server)
- block:
- name: ensure needed system users are present
user: name=admin comment="Freifunk MWU Admin" shell=/bin/bash state=present
- name: ensure all wanted ssh keys exclusively
authorized_key: exclusive=True state=present user=admin
key={{ mwu_s_admin_keys ~ ( h_v_add_auth_keys | default('') ) }}
- name: ensure vim is default editor
alternatives: name=editor path=/usr/bin/vim.basic
- name: set timezone to Europe/Berlin
timezone: name=Europe/Berlin
when: (ansible_managed_server is defined) and (ansible_managed_server)
# end block

View file

@ -1,30 +0,0 @@
---
# for package role :::::::::::::::::::::::::::::::::::::::::::::::::
# not def: server_pkg_repo_list
server_pkg_pkg_list:
- software-properties-common
- apt-transport-https
- man-db
- mosh
- ntp
- sudo
- sysfsutils
- vim
- vnstat
- vnstati
# not def: server_pkg_pip_list
# for tasks ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mwu_s_admin_keys: |
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEA2ProGXZXgOu1qAkY1COL4vvIdMpBAi/eg7/SvQRUrm1H8typyJHJPOvaMO8oz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BmDxfVyXM70M3922lx41w== juventas
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTwobxZo1wyRFUDZ32jM9AvCDUMTghSDAQMdffOrOaD8AAvVuaFzR6/yNvPHUhMOIb4CQPnaXGiTYumXRXRJrA9X2AgMSRuubySrpwkqRIje9HvQ1WfDdo4OWPYj/ArAlgxUqmLAyEjolmM8TY2aRvCPCrtE39oFfx5eCfLGkh0hn6wOGN7Gz8bh8P9n10ihYLrHhQsjEplXOX28b+9UojjjZX0Sfwk82u+/8f1y3ebT6kcPQx5OKqWU2GGbLgOOptkrguSu+vmF4KyxR9ayEqY2OpNdr7G+xp+4DC1pJhnIWq+GbcsH8xQVMDZPYaUjJQOiduRB0U5CqclSc22d39 belzebub

View file

@ -8,7 +8,6 @@ packages:
- mlocate - mlocate
- mosh - mosh
- python3-yaml - python3-yaml
- sudo
- sysfsutils - sysfsutils
- unattended-upgrades - unattended-upgrades
- vim - vim

21
roles/users/README.md Normal file
View file

@ -0,0 +1,21 @@
# Ansible role users
Diese Ansible role konfiguriert System- und Admin-Benutzer.
- installiert sudo
- stellt sicher, dass gewünschte Benutzer angelegt sind
- erstellt pro Benutzer eine sudoers Datei unter /etc/sudoers.d
## Benötigte Variablen
- Liste `system_users` # Pro Listeneintrag ein dict für System-Benutzer
- `name` # Benutzername
- `comment`
- `shell`
- `home`
- `state`
- `ssh_keys` # Erwartet eine Liste wie z.B. `ssh_keys_admin_team`
- Liste `admin_users` # Pro Listeneintrag ein dict für Admin-Benutzer
- Liste `ssh_keys_admin_team` # Pro Listeneintrag ein dict für Public Keys
- `name`
`ssh_public_key`

View file

@ -0,0 +1,6 @@
---
system_users:
admin_users:
ssh_keys_admin_team:

View file

@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTwobxZo1wyRFUDZ32jM9AvCDUMTghSDAQMdffOrOaD8AAvVuaFzR6/yNvPHUhMOIb4CQPnaXGiTYumXRXRJrA9X2AgMSRuubySrp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q0zoNyX/EizkPuG8IyK1MrVY1sOUVcQzFFV+PMn8DMWgJpm0eeXJyxa3KBTovtINsFCWfDWtojkB0aC5/XKZAbVC4pOKNRROctRpcdLERNqV9dZ5TkIriB1N2/Z48hjQPimjlFrR8+v1pt37YP/2lvAbOf1sTysu8ey9pFTt7jiiTR5NM= kaba

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAgwquzleAfo0ZccCikwh9aD0cBA0XrvEmQIB06XUUyn kokel

View file

@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9iZOonZ/WGmtgpZgs9vibpq6HJhpvuciBa8vzjysIYYiqNGgLvtZxw/2Af0/ykTdsP09A28RVGJXel6u8I2b16a0e+H2yBbUn8pXFow8xODPXezN0J/U7CDb8mRF9SkBJEzqVt1ndchJWU/qTi/nqbPfNaurB8EXkIDGcmDiCci25RVBDUvSSQBP+XIxQICJgeJ66CYcrD1Sry65H8tVSsWr6+fruNFZQRYyxAFu/7wW3J/RfFJQJFF9WNRzspChsjYRqrYdZCCx6GZ0qQxK4hwqfVbv3cPjZGFfcLrQaOCUMIiDUVEVmmdp0phE7eYDYewxD2Yaw1+fIJ+hWal6F moritz@wwwserv.de

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGom9IEjz5utkAWg2wSm0uk+JC0A2tFlz2coAAvA2/An prisma@oimelmobil

View file

@ -0,0 +1,49 @@
---
- name: ensure sudo is installed
package:
name: "sudo"
state: present
- name: ensure system users are present
user:
name: "{{ item.name }}"
comment: "{{ item.comment }}"
shell: "{{ item.shell }}"
home: "{{ item.home }}"
state: "{{ item.state }}"
with_items: "{{ system_users }}"
- name: ensure ssh config directory is present
file:
path: "{{ item.home }}/.ssh"
state: directory
owner: "{{ item.name }}"
group: "{{ item.name }}"
mode: '0700'
with_items: "{{ system_users }}"
- name: configure ssh public keys
template:
src: "authorized_keys.j2"
dest: "{{ item.home }}/.ssh/authorized_keys"
owner: "{{ item.name }}"
group: "{{ item.name }}"
mode: '0600'
with_items: "{{ system_users }}"
- name: configure passwordless sudo access
template:
src: "sudoers.j2"
dest: "/etc/sudoers.d/{{ item.name }}"
owner: root
group: root
mode: '0440'
validate: "/usr/sbin/visudo -cf %s"
with_items: "{{ system_users }}"
- name: remove admin lines from /etc/sudoers
lineinfile:
path: "/etc/sudoers"
state: absent
regexp: '^admin\s'
validate: "/usr/sbin/visudo -cf %s"

View file

@ -0,0 +1,3 @@
{% for key in item.ssh_keys %}
{{ key.ssh_public_key }}
{% endfor %}

View file

@ -0,0 +1,2 @@
# {{ ansible_managed }}
admin ALL=NOPASSWD: ALL

24
roles/users/vars/main.yml Normal file
View file

@ -0,0 +1,24 @@
---
system_users:
- name: "admin"
comment: "Freifunk Admin Account"
shell: "/bin/bash"
home: "/home/admin"
state: "present"
ssh_keys: "{{ ssh_keys_admin_team }}"
admin_users:
ssh_keys_admin_team:
- name: kaba
ssh_public_key: "{{ lookup('file', 'kaba.pub') }}"
- name: moritz
ssh_public_key: "{{ lookup('file', 'moritz.pub') }}"
- name: juventas
ssh_public_key: "{{ lookup('file', 'juventas.pub') }}"
- name: prisma
ssh_public_key: "{{ lookup('file', 'prisma.pub') }}"
- name: kokel
ssh_public_key: "{{ lookup('file', 'kokel.pub') }}"
- name: belzebub
ssh_public_key: "{{ lookup('file', 'belzebub.pub') }}"