From 541c061c7deea565cca73bf6b1341b42ee85a985 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sun, 9 Jan 2022 18:19:16 +0100 Subject: [PATCH] xrdp_apphost: Moved configuration to dictionary This allows config and user generation using loops --- roles/xrdp_apphost/defaults/main.yml | 46 +++++++++++-------- roles/xrdp_apphost/handlers/main.yml | 2 +- roles/xrdp_apphost/tasks/estlcam.yml | 10 ++-- roles/xrdp_apphost/tasks/lightburn.yml | 12 ++--- roles/xrdp_apphost/tasks/main.yml | 30 +++++------- roles/xrdp_apphost/tasks/slicer.yml | 12 ++--- .../templates/estlcam_xsession.j2 | 2 +- .../templates/lightburn_xsession.j2 | 2 +- .../xrdp_apphost/templates/slicer_xsession.j2 | 2 +- roles/xrdp_apphost/templates/smb.conf.j2 | 35 +++----------- .../templates/tsadmin_xsession.j2 | 6 +-- roles/xrdp_apphost/templates/xrdp.ini.j2 | 28 +++-------- 12 files changed, 75 insertions(+), 112 deletions(-) diff --git a/roles/xrdp_apphost/defaults/main.yml b/roles/xrdp_apphost/defaults/main.yml index 8a88787..77d679f 100644 --- a/roles/xrdp_apphost/defaults/main.yml +++ b/roles/xrdp_apphost/defaults/main.yml @@ -23,30 +23,36 @@ xrdp_ls_btn_cancel_y_pos: 370 info_folder_name: "___Files\ older\ than\ 30\ days\ will\ be\ automatically\ deleted" -lightburn_user: lightburn -lightburn_group: lightburn -lightburn_pass: fckgw01lightburn -lightburn_salt: $1$SomeSalt$ +xrdp_applications: + LightBurn: + user: lightburn + group: lightburn + pass: fckgw01lightburn + salt: $1$SomeSalt$ -lightburn_checksum: sha256:30d3cd573f5036edf74922ce56515304e668c345b5921fa0786248a8cc4be048 -lightburn_version: 1.0.04 -lightburn_url: https://github.com/LightBurnSoftware/deployment/releases/download/{{ lightburn_version }}/LightBurn-Linux64-v{{ lightburn_version }}.run -lightburn_target: /home/{{ lightburn_user }}/LightBurn-Linux64-v{{ lightburn_version }}.run + checksum: sha256:30d3cd573f5036edf74922ce56515304e668c345b5921fa0786248a8cc4be048 + version: 1.0.04 -estlcam_user: estlcam -estlcam_group: estlcam -estlcam_pass: fckgw01estlcam -estlcam_salt: $1$SomeSalt$ + Estlcam: + user: estlcam + group: estlcam + pass: fckgw01estlcam + salt: $1$SomeSalt$ -slicer_user: slicer -slicer_group: slicer -slicer_pass: fckgw01slicer -slicer_salt: $1$SomeSalt$ + Slicer: + user: slicer + group: slicer + pass: fckgw01slicer + salt: $1$SomeSalt$ -slicer_checksum: sha256:b6c34157ff2acffae5b39a1997f5694e9ca4717d5c9b370f75a6728eeadb9cab -slicer_version: 2.4.0+linux-x64-202112211614 -slicer_url: https://github.com/prusa3d/PrusaSlicer/releases/download/version_2.4.0/PrusaSlicer-{{ slicer_version }}.AppImage -slicer_target: /home/{{ slicer_user }}/PrusaSlicer-{{ slicer_version }}.AppImage + checksum: sha256:b6c34157ff2acffae5b39a1997f5694e9ca4717d5c9b370f75a6728eeadb9cab + version: 2.4.0+linux-x64-202112211614 + +lightburn_url: https://github.com/LightBurnSoftware/deployment/releases/download/{{ xrdp_applications.LightBurn.version }}/LightBurn-Linux64-v{{ xrdp_applications.LightBurn.version }}.run +lightburn_target: /home/{{ xrdp_applications.LightBurn.user }}/LightBurn-Linux64-v{{ xrdp_applications.LightBurn.version }}.run + +slicer_url: https://github.com/prusa3d/PrusaSlicer/releases/download/version_2.4.0/PrusaSlicer-{{ xrdp_applications.Slicer.version }}.AppImage +slicer_target: /home/{{ xrdp_applications.Slicer.user }}/PrusaSlicer-{{ xrdp_applications.Slicer.version }}.AppImage tsadmin_user: tsadmin tsadmin_group: tsadmin diff --git a/roles/xrdp_apphost/handlers/main.yml b/roles/xrdp_apphost/handlers/main.yml index 8c1af26..68f3653 100644 --- a/roles/xrdp_apphost/handlers/main.yml +++ b/roles/xrdp_apphost/handlers/main.yml @@ -6,7 +6,7 @@ - name: Install LightBurn shell: "{{ lightburn_target }}" become: yes - become_user: "{{ lightburn_user }}" + become_user: "{{ xrdp_applications.LightBurn.user }}" - name: Reload smbd service: name=smbd state=reloaded \ No newline at end of file diff --git a/roles/xrdp_apphost/tasks/estlcam.yml b/roles/xrdp_apphost/tasks/estlcam.yml index dd5a4eb..96738ba 100644 --- a/roles/xrdp_apphost/tasks/estlcam.yml +++ b/roles/xrdp_apphost/tasks/estlcam.yml @@ -24,20 +24,20 @@ - xfwm4 - name: Create Estlcam group - group: name={{ estlcam_group }} + group: name={{ xrdp_applications.Estlcam.group }} - name: Create Estlcam user - user: name={{ estlcam_user }} password={{ estlcam_pass | password_hash('sha512', estlcam_salt) }} home=/home/{{ estlcam_user }} group={{ estlcam_group }} + user: name={{ xrdp_applications.Estlcam.user }} password={{ xrdp_applications.Estlcam.pass | password_hash('sha512', xrdp_applications.Estlcam.salt) }} home=/home/{{ xrdp_applications.Estlcam.user }} group={{ xrdp_applications.Estlcam.group }} - name: Create Estlcam .xsession - template: src=estlcam_xsession.j2 dest=/home/{{ estlcam_user }}/.xsession + template: src=estlcam_xsession.j2 dest=/home/{{ xrdp_applications.Estlcam.user }}/.xsession - name: Create Estlcam data directory - file: path=/home/{{ estlcam_user }}/data state=directory mode=0755 owner={{ estlcam_user }} group={{ estlcam_group }} + file: path=/home/{{ xrdp_applications.Estlcam.user }}/data state=directory mode=0755 owner={{ xrdp_applications.Estlcam.user }} group={{ xrdp_applications.Estlcam.group }} - name: Create info directory file: - path: "/home/{{ estlcam_user }}/data/{{ info_folder_name }}" + path: "/home/{{ xrdp_applications.Estlcam.user }}/data/{{ info_folder_name }}" state: directory mode: 0444 owner: root diff --git a/roles/xrdp_apphost/tasks/lightburn.yml b/roles/xrdp_apphost/tasks/lightburn.yml index 3e40b0d..2b99598 100644 --- a/roles/xrdp_apphost/tasks/lightburn.yml +++ b/roles/xrdp_apphost/tasks/lightburn.yml @@ -7,25 +7,25 @@ - libnss3 - name: Create LightBurn group - group: name={{ lightburn_group }} + group: name={{ xrdp_applications.LightBurn.group }} - name: Create LightBurn user - user: name={{ lightburn_user }} password={{ lightburn_pass | password_hash('sha512', lightburn_salt) }} home=/home/{{ lightburn_user }} group={{ lightburn_group }} + user: name={{ xrdp_applications.LightBurn.user }} password={{ xrdp_applications.LightBurn.pass | password_hash('sha512', xrdp_applications.LightBurn.salt) }} home=/home/{{ xrdp_applications.LightBurn.user }} group={{ xrdp_applications.LightBurn.group }} - name: Create LightBurn .xsession - template: src=lightburn_xsession.j2 dest=/home/{{ lightburn_user }}/.xsession + template: src=lightburn_xsession.j2 dest=/home/{{ xrdp_applications.LightBurn.user }}/.xsession - name: Create LightBurn data directory - file: path=/home/{{ lightburn_user }}/data state=directory mode=0755 owner={{ lightburn_user }} group={{ lightburn_group }} + file: path=/home/{{ xrdp_applications.LightBurn.user }}/data state=directory mode=0755 owner={{ xrdp_applications.LightBurn.user }} group={{ xrdp_applications.LightBurn.group }} - name: Create info directory file: - path: "/home/{{ lightburn_user }}/data/{{ info_folder_name }}" + path: "/home/{{ xrdp_applications.LightBurn.user }}/data/{{ info_folder_name }}" state: directory mode: 0444 owner: root group: root - name: Download LightBurn binary - get_url: url={{ lightburn_url }} dest={{ lightburn_target }} checksum={{ lightburn_checksum }} mode=0755 + get_url: url={{ lightburn_url }} dest={{ lightburn_target }} checksum={{ xrdp_applications.LightBurn.checksum }} mode=0755 notify: Install LightBurn \ No newline at end of file diff --git a/roles/xrdp_apphost/tasks/main.yml b/roles/xrdp_apphost/tasks/main.yml index bc66848..9a2f560 100644 --- a/roles/xrdp_apphost/tasks/main.yml +++ b/roles/xrdp_apphost/tasks/main.yml @@ -25,13 +25,11 @@ lineinfile: dest: /etc/sudoers state: present - regexp: '^{{ tsadmin_user }} ALL=({{ item }}) NOPASSWD: ALL' - line: '{{ tsadmin_user }} ALL=({{ item }}) NOPASSWD: ALL' + regexp: '^{{ tsadmin_user }} ALL=({{ item.value.user }}) NOPASSWD: ALL' + line: '{{ tsadmin_user }} ALL=({{ item.value.user }}) NOPASSWD: ALL' validate: visudo -cf %s - with_items: - - "{{ estlcam_user }}" - - "{{ lightburn_user }}" - - "{{ slicer_user }}" + with_dict: + - "{{ xrdp_applications }}" - name: Create tsadmin_user .xsession template: src=tsadmin_xsession.j2 dest=/home/{{ tsadmin_user }}/.xsession @@ -41,21 +39,17 @@ name: "Delete files older than 30 days" minute: "0" hour: "5" - job: "find /home/{{ item }}/data -type f -mtime +30 ! -name \"{{ info_folder_name }}\" -delete" - user: "{{ item }}" - with_items: - - "{{ estlcam_user }}" - - "{{ lightburn_user }}" - - "{{ slicer_user }}" + job: "find /home/{{ item.value.user }}/data -type f -mtime +30 ! -name \"{{ info_folder_name }}\" -delete" + user: "{{ item.value.user }}" + with_dict: + - "{{ xrdp_applications }}" - name: Create directory cleanup cron cron: name: "Delete empty directories" minute: "1" hour: "5" - job: "find /home/{{ item }}/data -type d -empty ! -name \"{{ info_folder_name }}\" -delete" - user: "{{ item }}" - with_items: - - "{{ estlcam_user }}" - - "{{ lightburn_user }}" - - "{{ slicer_user }}" + job: "find /home/{{ item.value.user }}/data -type d -empty ! -name \"{{ info_folder_name }}\" -delete" + user: "{{ item.value.user }}" + with_dict: + - "{{ xrdp_applications }}" diff --git a/roles/xrdp_apphost/tasks/slicer.yml b/roles/xrdp_apphost/tasks/slicer.yml index 39ce04f..86ce467 100644 --- a/roles/xrdp_apphost/tasks/slicer.yml +++ b/roles/xrdp_apphost/tasks/slicer.yml @@ -6,24 +6,24 @@ - libgtk2.0-0 - name: Create Slic3r group - group: name={{ slicer_group }} + group: name={{ xrdp_applications.Slicer.group }} - name: Create Slic3r user - user: name={{ slicer_user }} password={{ slicer_pass | password_hash('sha512', slicer_salt) }} home=/home/{{ slicer_user }} group={{ slicer_group }} + user: name={{ xrdp_applications.Slicer.user }} password={{ xrdp_applications.Slicer.pass | password_hash('sha512', xrdp_applications.Slicer.salt) }} home=/home/{{ xrdp_applications.Slicer.user }} group={{ xrdp_applications.Slicer.group }} - name: Create Slic3r .xsession - template: src=slicer_xsession.j2 dest=/home/{{ slicer_user }}/.xsession + template: src=slicer_xsession.j2 dest=/home/{{ xrdp_applications.Slicer.user }}/.xsession - name: Create Slic3r data directory - file: path=/home/{{ slicer_user }}/data state=directory mode=0755 owner={{ slicer_user }} group={{ slicer_group }} + file: path=/home/{{ xrdp_applications.Slicer.user }}/data state=directory mode=0755 owner={{ xrdp_applications.Slicer.user }} group={{ xrdp_applications.Slicer.group }} - name: Create info directory file: - path: "/home/{{ slicer_user }}/data/{{ info_folder_name }}" + path: "/home/{{ xrdp_applications.Slicer.user }}/data/{{ info_folder_name }}" state: directory mode: 0444 owner: root group: root - name: Download Slic3r binary - get_url: url={{ slicer_url }} dest={{ slicer_target }} checksum={{ slicer_checksum }} mode=0755 + get_url: url={{ slicer_url }} dest={{ slicer_target }} checksum={{ xrdp_applications.Slicer.checksum }} mode=0755 diff --git a/roles/xrdp_apphost/templates/estlcam_xsession.j2 b/roles/xrdp_apphost/templates/estlcam_xsession.j2 index 811185e..ec82538 100644 --- a/roles/xrdp_apphost/templates/estlcam_xsession.j2 +++ b/roles/xrdp_apphost/templates/estlcam_xsession.j2 @@ -2,4 +2,4 @@ export WINEPREFIX=~/.wine32 xfwm4 & -exec wine "/home/{{ estlcam_user }}/.wine32/drive_c/Program Files/Estlcam11/Estlcam.exe" \ No newline at end of file +exec wine "/home/{{ xrdp_applications.Estlcam.user }}/.wine32/drive_c/Program Files/Estlcam11/Estlcam.exe" \ No newline at end of file diff --git a/roles/xrdp_apphost/templates/lightburn_xsession.j2 b/roles/xrdp_apphost/templates/lightburn_xsession.j2 index 64b3107..6705c5c 100644 --- a/roles/xrdp_apphost/templates/lightburn_xsession.j2 +++ b/roles/xrdp_apphost/templates/lightburn_xsession.j2 @@ -1,4 +1,4 @@ {{ ansible_managed | comment }} matchbox-window-manager & -exec /home/{{ lightburn_user }}/.local/share/LightBurn/LightBurn \ No newline at end of file +exec /home/{{ xrdp_applications.LightBurn.user }}/.local/share/LightBurn/LightBurn \ No newline at end of file diff --git a/roles/xrdp_apphost/templates/slicer_xsession.j2 b/roles/xrdp_apphost/templates/slicer_xsession.j2 index fc427d1..b63f929 100644 --- a/roles/xrdp_apphost/templates/slicer_xsession.j2 +++ b/roles/xrdp_apphost/templates/slicer_xsession.j2 @@ -1,4 +1,4 @@ {{ ansible_managed | comment }} matchbox-window-manager & -exec /home/{{ slicer_user }}/PrusaSlicer-{{ slicer_version }}.AppImage \ No newline at end of file +exec /home/{{ xrdp_applications.Slicer.user }}/PrusaSlicer-{{ xrdp_applications.Slicer.version }}.AppImage \ No newline at end of file diff --git a/roles/xrdp_apphost/templates/smb.conf.j2 b/roles/xrdp_apphost/templates/smb.conf.j2 index 3e5df72..73a7764 100644 --- a/roles/xrdp_apphost/templates/smb.conf.j2 +++ b/roles/xrdp_apphost/templates/smb.conf.j2 @@ -236,38 +236,17 @@ # to the drivers directory for these users to have write rights in it ; write list = root, @lpadmin -# LightBurn share -[lightburn] - comment = LightBurn data folder - path = /home/{{ lightburn_user }}/data +{% for app, config in xrdp_applications.items() %} +# {{ app}} share +[{{ app | lower }}] + comment = {{ app }} data folder + path = /home/{{ config.user }}/data browseable = yes read only = no guest ok = yes create mask = 0600 directory mask = 0700 - force user = {{ lightburn_user }} + force user = {{ config.user }} hide dot files = yes -# Estlcam share -[estlcam] - comment = Estlcam data folder - path = /home/{{ estlcam_user }}/data - browseable = yes - read only = no - guest ok = yes - create mask = 0600 - directory mask = 0700 - force user = {{ estlcam_user }} - hide dot files = yes - -# Slicer share -[slicer] - comment = Slicer data folder - path = /home/{{ slicer_user }}/data - browseable = yes - read only = no - guest ok = yes - create mask = 0600 - directory mask = 0700 - force user = {{ slicer_user }} - hide dot files = yes \ No newline at end of file +{% endfor %} \ No newline at end of file diff --git a/roles/xrdp_apphost/templates/tsadmin_xsession.j2 b/roles/xrdp_apphost/templates/tsadmin_xsession.j2 index d7f2461..b705a44 100644 --- a/roles/xrdp_apphost/templates/tsadmin_xsession.j2 +++ b/roles/xrdp_apphost/templates/tsadmin_xsession.j2 @@ -1,7 +1,7 @@ {{ ansible_managed | comment }} -xhost si:localuser:{{ lightburn_user }} -xhost si:localuser:{{ estlcam_user }} -xhost si:localuser:{{ slicer_user }} +{% for app, config in xrdp_applications.items() %} +xhost si:localuser:{{ config.user }} +{% endfor %} xfwm4 & exec xterm \ No newline at end of file diff --git a/roles/xrdp_apphost/templates/xrdp.ini.j2 b/roles/xrdp_apphost/templates/xrdp.ini.j2 index e75d61c..766fbad 100644 --- a/roles/xrdp_apphost/templates/xrdp.ini.j2 +++ b/roles/xrdp_apphost/templates/xrdp.ini.j2 @@ -182,33 +182,17 @@ tcutils=true ; Some session types such as Xorg, X11rdp and Xvnc start a display server. ; Startup command-line parameters for the display server are configured ; in sesman.ini. See and configure also sesman.ini. -[LightBurn] -name=LightBurn +{% for app, config in xrdp_applications.items() %} +[{{ app }}] +name={{ app }} lib=libxup.so -username={{ lightburn_user }} -password={{ lightburn_pass }} -ip=127.0.0.1 -port=-1 -code=20 - -[Estlcam] -name=Estlcam -lib=libxup.so -username={{ estlcam_user }} -password={{ estlcam_pass }} -ip=127.0.0.1 -port=-1 -code=20 - -[Slicer] -name=Slicer -lib=libxup.so -username={{ slicer_user }} -password={{ slicer_pass }} +username={{ config.user }} +password={{ config.pass }} ip=127.0.0.1 port=-1 code=20 +{% endfor %} [Xorg] name=Xorg lib=libxup.so