From 1d1734f7ec7f715ca35413a42494b78e43ae0507 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Thu, 3 Apr 2025 02:36:50 +0200 Subject: [PATCH] feat(repo): Initial commit --- .gitignore | 1 + LICENSE | 9 +++ README.md | 35 ++++++++++ .../proxmoxlib.js.patch | 14 ++++ handlers/main.yml | 32 +++++++++ meta/main.yml | 10 +++ tasks/main.yml | 8 +++ tasks/repo-disable-ceph-enterprise.yml | 23 ++++++ tasks/repo-disable-pve-enterprise.yml | 23 ++++++ tasks/repo-enable-free.yml | 28 ++++++++ tasks/repo-enable-non-free.yml | 8 +++ tasks/repo-remove-nag-screen.yml | 8 +++ tasks/web-ui-get-git-repo-for-reloads.yml | 11 +++ tasks/web-ui-port-443.yml | 70 +++++++++++++++++++ .../etc/nginx/sites-available/proxmox.conf.j2 | 31 ++++++++ 15 files changed, 311 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 files/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.patch create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tasks/repo-disable-ceph-enterprise.yml create mode 100644 tasks/repo-disable-pve-enterprise.yml create mode 100644 tasks/repo-enable-free.yml create mode 100644 tasks/repo-enable-non-free.yml create mode 100644 tasks/repo-remove-nag-screen.yml create mode 100644 tasks/web-ui-get-git-repo-for-reloads.yml create mode 100644 tasks/web-ui-port-443.yml create mode 100644 templates/etc/nginx/sites-available/proxmox.conf.j2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..01c4217 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 quico-ansible + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7c5c09 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +[//]: # (SPDX-License-Identifier: MIT) +# Role Name + +role-service-proxmox_virtual_environment + +# Description + +Set up a Proxmox instance. + +# Requirements + +Target machines must have Proxmox installed and running. + +# Role Variables + +None. + +# Dependencies + +None. + +# Example Playbook + +In your `playbook.yml` call it like so: + +``` +- name: 'Awesome playbook' + hosts: all + roles: + - 'role-service-proxmox_virtual_environment' +``` + +# License + +MIT diff --git a/files/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.patch b/files/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.patch new file mode 100644 index 0000000..9d86e21 --- /dev/null +++ b/files/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.patch @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: MIT +--- proxmoxlib.js.orig 2024-11-19 12:40:04.000000000 +0100 ++++ proxmoxlib.js 2024-12-25 08:54:10.283639449 +0100 +@@ -575,8 +575,8 @@ + let res = response.result; + if (res === null || res === undefined || !res || res + .data.status.toLowerCase() !== 'active') { +- Ext.Msg.show({ +- title: gettext('No valid subscription'), ++ void({ ++ title: gettext('No valid subscription'), + icon: Ext.Msg.WARNING, + message: Proxmox.Utils.getNoSubKeyHtml(res.data.url), + buttons: Ext.Msg.OK, diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..6b9d73e --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: MIT +- name: 'Reload systemd unit configs' + ansible.builtin.systemd_service: + daemon_reload: true + listen: 'Reload all systemd services' + +- name: 'Restart pveproxy.service' + ansible.builtin.service: + name: 'pveproxy.service' + state: 'restarted' + listen: 'Restart all Proxmox Virtual Environment services' + +- name: 'Validate Nginx config' + ansible.builtin.shell: | + nginx -t + listen: + - 'Restart all Proxmox Virtual Environment services' + - 'Reload web server' + +- name: 'Restart nginx.service' + ansible.builtin.service: + name: 'nginx.service' + state: 'reloaded' + listen: + - 'Restart all Proxmox Virtual Environment services' + - 'Reload web server' + +- name: 'apt-get update' + ansible.builtin.apt: + update_cache: yes + listen: + - 'apt-get update' diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..d7d196b --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT +galaxy_info: + author: 'hygienic-books' + description: 'Set up a Proxmox instance' + license: MIT + min_ansible_version: 2.18.1 + galaxy_tags: + - 'proxmox' + - 'virtualization' +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..c5d569b --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +- import_tasks: 'repo-enable-free.yml' +- import_tasks: 'repo-enable-non-free.yml' +- import_tasks: 'repo-disable-pve-enterprise.yml' +- import_tasks: 'repo-disable-ceph-enterprise.yml' +- import_tasks: 'repo-remove-nag-screen.yml' +- import_tasks: 'web-ui-get-git-repo-for-reloads.yml' +- import_tasks: 'web-ui-port-443.yml' diff --git a/tasks/repo-disable-ceph-enterprise.yml b/tasks/repo-disable-ceph-enterprise.yml new file mode 100644 index 0000000..f5a1a5d --- /dev/null +++ b/tasks/repo-disable-ceph-enterprise.yml @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: MIT +- name: 'Check if Ceph enterprise repo is present' + register: 'pve_apt_repo_files_with_ceph_enterprise_repo' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("enterprise")) | .path' + +- name: 'If Ceph enterprise repo is present check if Ceph enterprise repo is enabled' + when: 'pve_apt_repo_files_with_ceph_enterprise_repo.stdout_lines | length > 0' + register: 'pve_apt_repo_files_ceph_enterprise_repo_enabled_state' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("enterprise")) | .repositories[] | select(.Components | index("enterprise")) | .Enabled' + +- name: 'If Ceph enterprise repo is enabled disable Ceph enterprise repo' + when: 'pve_apt_repo_files_ceph_enterprise_repo_enabled_state.stdout == "1"' + loop_control: + loop_var: 'apt_repo_file' + label: 'Disable Ceph enterprise repo in {{ apt_repo_file | regex_replace(''"'', "''") }}' + loop: '{{ pve_apt_repo_files_with_ceph_enterprise_repo.stdout_lines }}' + ansible.builtin.shell: | + index_in_file="$(pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.path=={{ apt_repo_file }}) | .repositories | map(.Components | index("enterprise")) | index(0)')" + pvesh create /nodes/{{ inventory_hostname_short }}/apt/repositories -index "${index_in_file}" -path {{ apt_repo_file }} -enabled 'false' diff --git a/tasks/repo-disable-pve-enterprise.yml b/tasks/repo-disable-pve-enterprise.yml new file mode 100644 index 0000000..ac9645a --- /dev/null +++ b/tasks/repo-disable-pve-enterprise.yml @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: MIT +- name: 'Check if pve-enterprise repo is present' + register: 'pve_apt_repo_files_with_pve_enterprise_repo' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-enterprise")) | .path' + +- name: 'If pve-enterprise repo is present check if pve-enterprise repo is enabled' + when: 'pve_apt_repo_files_with_pve_enterprise_repo.stdout_lines | length > 0' + register: 'pve_apt_repo_files_pve_enterprise_repo_enabled_state' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-enterprise")) | .repositories[] | select(.Components | index("pve-enterprise")) | .Enabled' + +- name: 'If pve-enterprise repo is enabled disable pve-enterprise repo' + when: 'pve_apt_repo_files_pve_enterprise_repo_enabled_state.stdout == "1"' + loop_control: + loop_var: 'apt_repo_file' + label: 'Disable pve-enterprise repo in {{ apt_repo_file | regex_replace(''"'', "''") }}' + loop: '{{ pve_apt_repo_files_with_pve_enterprise_repo.stdout_lines }}' + ansible.builtin.shell: | + index_in_file="$(pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.path=={{ apt_repo_file }}) | .repositories | map(.Components | index("pve-enterprise")) | index(0)')" + pvesh create /nodes/{{ inventory_hostname_short }}/apt/repositories -index "${index_in_file}" -path {{ apt_repo_file }} -enabled 'false' diff --git a/tasks/repo-enable-free.yml b/tasks/repo-enable-free.yml new file mode 100644 index 0000000..d2b63e4 --- /dev/null +++ b/tasks/repo-enable-free.yml @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: MIT +- name: 'Check if pve-no-subscription repo is present' + register: 'pve_apt_repo_files_with_pve_free_repo' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-no-subscription")) | .path' + +- name: 'If pve-no-subscription repo is present check if pve-no-subscription repo is enabled' + when: 'pve_apt_repo_files_with_pve_free_repo.stdout_lines | length > 0' + register: 'pve_apt_repo_files_free_repo_enabled_state' + changed_when: false + ansible.builtin.shell: | + pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-no-subscription")) | .repositories[] | select(.Components | index("pve-no-subscription")) | .Enabled' + +- name: 'If pve-no-subscription repo is disabled enable pve-no-subscription repo' + when: 'pve_apt_repo_files_free_repo_enabled_state.stdout == "0"' + loop_control: + loop_var: 'apt_repo_file' + label: 'Enable pve-no-subscription repo in {{ apt_repo_file | regex_replace(''"'', "''") }}' + loop: '{{ pve_apt_repo_files_with_pve_free_repo.stdout_lines }}' + ansible.builtin.shell: | + index_in_file="$(pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.path=={{ apt_repo_file }}) | .repositories | map(.Components | index("pve-no-subscription")) | index(0)')" + pvesh create /nodes/{{ inventory_hostname_short }}/apt/repositories -index "${index_in_file}" -path {{ apt_repo_file }} -enabled 'true' + +- name: 'If pve-no-subscription repo is not present add pve-no-subscription repo' + when: 'pve_apt_repo_files_with_pve_free_repo.stdout_lines | length == 0' + ansible.builtin.shell: | + pvesh set /nodes/{{ inventory_hostname_short }}/apt/repositories -handle 'no-subscription' diff --git a/tasks/repo-enable-non-free.yml b/tasks/repo-enable-non-free.yml new file mode 100644 index 0000000..916a939 --- /dev/null +++ b/tasks/repo-enable-non-free.yml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +- name: 'In ''/etc/apt/sources.list'' enable non-free component in all Debian-native repos' + ansible.builtin.replace: + path: '/etc/apt/sources.list' + regexp: '^(.*?)( main contrib(?! non-free))' + replace: '\g<1>\g<2> non-free' + notify: + - 'apt-get update' diff --git a/tasks/repo-remove-nag-screen.yml b/tasks/repo-remove-nag-screen.yml new file mode 100644 index 0000000..7586e78 --- /dev/null +++ b/tasks/repo-remove-nag-screen.yml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +- name: 'Patch proxmoxlib.js to no longer show no-subscription warning on web UI login' + ansible.posix.patch: + src: 'usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.patch' + basedir: '/usr/share/javascript/proxmox-widget-toolkit' + backup: true + notify: + - 'Restart pveproxy.service' diff --git a/tasks/web-ui-get-git-repo-for-reloads.yml b/tasks/web-ui-get-git-repo-for-reloads.yml new file mode 100644 index 0000000..3fc284c --- /dev/null +++ b/tasks/web-ui-get-git-repo-for-reloads.yml @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: MIT +- name: 'Create dir for ACME helper scripts Git repo' + ansible.builtin.file: + path: '/opt/git/quico.space/Quico/acme-deploy-helpers/branches/main' + state: 'directory' + + +- name: 'Git clone ACME helper scripts repo' + ansible.builtin.git: + repo: 'https://quico.space/Quico/acme-deploy-helpers.git' + dest: '/opt/git/quico.space/Quico/acme-deploy-helpers/branches/main' diff --git a/tasks/web-ui-port-443.yml b/tasks/web-ui-port-443.yml new file mode 100644 index 0000000..4f56a65 --- /dev/null +++ b/tasks/web-ui-port-443.yml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: MIT +- name: 'Install Nginx web server' + when: 'ansible_facts[''system''] | lower == ''linux''' + ansible.builtin.package: + name: + - 'nginx' + state: 'present' + notify: + - 'Reload web server' + +- name: 'Remove Nginx'' default config file' + ansible.builtin.file: + path: '/etc/nginx/sites-enabled/default' + state: 'absent' + notify: + - 'Reload web server' + +- name: 'Add Nginx config file for Proxmox web interface on port 443' + ansible.builtin.template: + src: 'etc/nginx/sites-available/proxmox.conf.j2' + dest: '/etc/nginx/sites-available/proxmox.conf' + notify: + - 'Reload web server' + +- name: 'Activate Nginx config file for Proxmox web interface on port 443' + ansible.builtin.file: + src: '../sites-available/proxmox.conf' + dest: '/etc/nginx/sites-enabled/proxmox.conf' + state: 'link' + notify: + - 'Reload web server' + +- name: 'Create systemd override dir for nginx.service' + ansible.builtin.file: + path: '/etc/systemd/system/nginx.service.d' + state: 'directory' + mode: '0755' + notify: + - 'Reload systemd unit configs' + - 'Reload web server' + +- name: 'Make sure nginx.service only starts after its certs dir is available provided by pve-cluster.service' + loop_control: + loop_var: 'config' + index_var: 'i' + label: 'Set systemd override.conf ''{{ config.key }}={{ config.value }}'' setting' + loop: + - { key: 'Requires', value: 'pve-cluster.service' } + - { key: 'After', value: 'pve-cluster.service' } + community.general.ini_file: + path: '/etc/systemd/system/nginx.service.d/override.conf' + owner: 'root' + group: 'root' + mode: '0644' + no_extra_spaces: true + section: 'Unit' + option: '{{ config.key }}' + value: '{{ config.value }}' + notify: + - 'Reload systemd unit configs' + - 'Reload web server' + +- name: 'Flush handlers' + meta: 'flush_handlers' + +- name: 'Start Nginx web server' + ansible.builtin.service: + name: 'nginx.service' + state: 'started' + enabled: true diff --git a/templates/etc/nginx/sites-available/proxmox.conf.j2 b/templates/etc/nginx/sites-available/proxmox.conf.j2 new file mode 100644 index 0000000..24f0103 --- /dev/null +++ b/templates/etc/nginx/sites-available/proxmox.conf.j2 @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: MIT +upstream proxmox { + server "{{ ansible_facts['fqdn'] }}"; +} + +server { + listen 80 default_server; + listen [::]:80 default_server; + rewrite ^(.*) https://$host$1 permanent; +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name _; + ssl_certificate /etc/ssl/private/{{ ansible_facts['fqdn'] }}_fullchain.cer; + ssl_certificate_key /etc/ssl/private/{{ ansible_facts['fqdn'] }}.key; + proxy_redirect off; + location / { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_pass https://localhost:8006; + proxy_buffering off; + client_max_body_size 0; + proxy_connect_timeout 3600s; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + send_timeout 3600s; + } +}