From 498037625ae820c0dd67212811434c3d8ecc3782 Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Sun, 8 Mar 2020 20:56:46 +0100 Subject: [PATCH] fix wrong db definition - fix uninstall - fix when variable undefined --- README.md | 6 +++--- libreschool-adminusers.spec | 2 ++ root/etc/ansible/roles/adminusers/tasks/main.yml | 14 +++++++------- .../defaults/{ansibleusers => adminusers}/password | 0 .../db/configuration/defaults/adminusers/sshkey | 0 .../defaults/{ansibleusers => adminusers}/type | 0 .../defaults/{ansibleusers => adminusers}/username | 0 7 files changed, 12 insertions(+), 10 deletions(-) rename root/etc/e-smith/db/configuration/defaults/{ansibleusers => adminusers}/password (100%) create mode 100644 root/etc/e-smith/db/configuration/defaults/adminusers/sshkey rename root/etc/e-smith/db/configuration/defaults/{ansibleusers => adminusers}/type (100%) rename root/etc/e-smith/db/configuration/defaults/{ansibleusers => adminusers}/username (100%) diff --git a/README.md b/README.md index ca2ed9c..93ffa44 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ You can set a password and an ssh key. Set the username (this is the default): ```bash -# db configuration setprop ansibleusers username libreschool +# db configuration setprop adminusers username libreschool ``` The default password is **"LibreSchool,1234"**. @@ -28,13 +28,13 @@ Set the password (must be hashed, see [here](https://docs.ansible.com/ansible/la localhost | SUCCESS => { "msg": "$6$S8BJ2Bbc26fRtExf$hNjphQ2HhbeiKLhPOdHttx6vWZwB90KgeinpREGrgcOHW2qYxf9s/csC7LFoENskhzwXK0wcWV3X9rPTC57Vu." } -# db configuration setprop ansibleusers password '$6$S8BJ2Bbc26fRtExf$hNjphQ2HhbeiKLhPOdHttx6vWZwB90KgeinpREGrgcOHW2qYxf9s/csC7LFoENskhzwXK0wcWV3X9rPTC57Vu.' +# db configuration setprop adminusers password '$6$S8BJ2Bbc26fRtExf$hNjphQ2HhbeiKLhPOdHttx6vWZwB90KgeinpREGrgcOHW2qYxf9s/csC7LFoENskhzwXK0wcWV3X9rPTC57Vu.' ``` Set an ssh key: ```bash -# db configuration setprop ansibleusers sshkey "$(cat ~/.ssh/id_rsa.pub)" +# db configuration setprop adminusers sshkey "$(cat ~/.ssh/id_rsa.pub)" ``` ## TODO / ideas ## diff --git a/libreschool-adminusers.spec b/libreschool-adminusers.spec index 43a8c3c..9114f55 100644 --- a/libreschool-adminusers.spec +++ b/libreschool-adminusers.spec @@ -34,6 +34,7 @@ echo "%doc COPYING" >> %{name}-%{version}-%{release} %defattr(-,root,root) %post +/etc/e-smith/events/actions/initialize-default-databases /sbin/e-smith/expand-template /etc/ansible/reconfigure_clients.yml %postun @@ -42,6 +43,7 @@ echo "%doc COPYING" >> %{name}-%{version}-%{release} #fi if [ "$1" = 0 ]; then #uninstallation + /sbin/e-smith/db configuration delete adminusers /sbin/e-smith/expand-template /etc/ansible/reconfigure_clients.yml fi diff --git a/root/etc/ansible/roles/adminusers/tasks/main.yml b/root/etc/ansible/roles/adminusers/tasks/main.yml index 3b790a2..5c69b73 100644 --- a/root/etc/ansible/roles/adminusers/tasks/main.yml +++ b/root/etc/ansible/roles/adminusers/tasks/main.yml @@ -2,20 +2,20 @@ - name: Create Admin user user: - name: "{{ esmith.ansibleusers.username }}" + name: "{{ esmith.adminusers.username }}" groups: adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare append: yes state: present - name: Set Admin password user: - name: "{{ esmith.ansibleusers.username }}" - password: "{{ esmith.ansibleusers.password }}" - when: esmith.ansibleusers.password != "" + name: "{{ esmith.adminusers.username }}" + password: "{{ esmith.adminusers.password }}" + when: (esmith.adminusers.password is defined) and (esmith.adminusers.password|length > 0) - name: Set authorized_key authorized_key: - user: "{{ esmith.ansibleusers.username }}" + user: "{{ esmith.adminusers.username }}" state: present - key: "{{ esmith.ansibleusers.sshkey }}" - when: esmith.ansibleusers.sshkey != "" + key: "{{ esmith.adminusers.sshkey }}" + when: (esmith.adminusers.sshkey is defined) and (esmith.adminusers.sshkey|length > 0) diff --git a/root/etc/e-smith/db/configuration/defaults/ansibleusers/password b/root/etc/e-smith/db/configuration/defaults/adminusers/password similarity index 100% rename from root/etc/e-smith/db/configuration/defaults/ansibleusers/password rename to root/etc/e-smith/db/configuration/defaults/adminusers/password diff --git a/root/etc/e-smith/db/configuration/defaults/adminusers/sshkey b/root/etc/e-smith/db/configuration/defaults/adminusers/sshkey new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/e-smith/db/configuration/defaults/ansibleusers/type b/root/etc/e-smith/db/configuration/defaults/adminusers/type similarity index 100% rename from root/etc/e-smith/db/configuration/defaults/ansibleusers/type rename to root/etc/e-smith/db/configuration/defaults/adminusers/type diff --git a/root/etc/e-smith/db/configuration/defaults/ansibleusers/username b/root/etc/e-smith/db/configuration/defaults/adminusers/username similarity index 100% rename from root/etc/e-smith/db/configuration/defaults/ansibleusers/username rename to root/etc/e-smith/db/configuration/defaults/adminusers/username