From 75b32e60aad2bc2d8d1746be1dbc6d6bf422592e Mon Sep 17 00:00:00 2001 From: binary Date: Thu, 19 Nov 2020 14:13:28 +0100 Subject: Move roles functionnality in sub-roles --- roles/users/tasks/main.yml | 38 ++++++++++++++++++++++++++++++++++++++ roles/users/templates/doas.conf.j2 | 6 ++++++ 2 files changed, 44 insertions(+) create mode 100644 roles/users/tasks/main.yml create mode 100644 roles/users/templates/doas.conf.j2 (limited to 'roles/users') diff --git a/roles/users/tasks/main.yml b/roles/users/tasks/main.yml new file mode 100644 index 0000000..0a0e259 --- /dev/null +++ b/roles/users/tasks/main.yml @@ -0,0 +1,38 @@ + +# users ~~ roles/users/tasks/main.yml +# Manage default users + +--- + +- name: retrieve available users + shell: awk -F ":" '{ if($3 == 0 || $3 > 999 && $3 < 16000) { print $1 }}' /etc/passwd + register: valid_users_shell + +- name: change shell to zsh for all valid users + user: name="{{ item }}" shell="{{ path_zsh }}" + loop: "{{ valid_users_shell.stdout_lines }}" + +- name: add operator user + user: + name: "{{ user_op }}" + comment: Operator user + group: "{{ group_root }}" + +- name: remove default users + user: + name: "{{ item }}" + state: absent + remove: true + loop: + - toor + - pi + +- name: generate doas configuration + template: + src: doas.conf.j2 + dest: "{{ path_doasconfig }}" + owner: root + group: "{{ group_root }}" + mode: 0644 + when: ansible_become_method == "doas" + diff --git a/roles/users/templates/doas.conf.j2 b/roles/users/templates/doas.conf.j2 new file mode 100644 index 0000000..51ee4cf --- /dev/null +++ b/roles/users/templates/doas.conf.j2 @@ -0,0 +1,6 @@ + +# doas ~~ /etc/doas.conf +# managed by Ansible + +permit keepenv nopass root +permit keepenv nopass {{ user_op }} as root -- cgit v1.2.3