feat(repo): Initial commit

This commit is contained in:
hygienic-books 2025-04-03 02:36:50 +02:00
commit 1d1734f7ec
15 changed files with 311 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

9
LICENSE Normal file
View File

@ -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.

35
README.md Normal file
View File

@ -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

View File

@ -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,

32
handlers/main.yml Normal file
View File

@ -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'

10
meta/main.yml Normal file
View File

@ -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: []

8
tasks/main.yml Normal file
View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

70
tasks/web-ui-port-443.yml Normal file
View File

@ -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

View File

@ -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;
}
}