diff --git a/inventory/group_vars/all/main.yaml b/inventory/group_vars/all/main.yaml index 2fdf97c..8b7e6a1 100644 --- a/inventory/group_vars/all/main.yaml +++ b/inventory/group_vars/all/main.yaml @@ -2,3 +2,4 @@ ansible_become_passwd: "{{ ansible_password }}" human_admin_user: max +proxmox_1_host: 192.168.0.2 diff --git a/inventory/hosts.yaml b/inventory/hosts.yaml index 6c4f7f7..c9a3be0 100644 --- a/inventory/hosts.yaml +++ b/inventory/hosts.yaml @@ -1,17 +1,41 @@ --- -physical: - hosts: - localhost: - ansible_become_password: "{{ ansible_become_passwd }}" - ansible_connection: local - ansible_python_interpreter: "{{ ansible_playbook_python }}" - 192.168.0.6: - ansible_become_password: "{{ ansible_become_passwd }}" - 192.168.0.8: - ansible_become_password: "{{ ansible_become_passwd }}" - 192.168.0.12: - ansible_become_password: "{{ ansible_become_passwd }}" - 192.168.0.16: - ansible_become_password: "{{ ansible_become_passwd }}" - 192.168.0.39: - ansible_become_password: "{{ ansible_become_passwd }}" +all: + children: + physical: + proxmox_1: + ansible_host: "{{ proxmox_1_host }}" + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + virtual: + hosts: + localhost: + ansible_become_password: "{{ ansible_become_passwd }}" + ansible_connection: local + ansible_python_interpreter: "{{ ansible_playbook_python }}" + services_to_run: + - webhook + nfs-server: + ansible_host: 192.168.0.6 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + jellyfin: + ansible_host: 192.168.0.8 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + frigate: + ansible_host: 192.168.0.12 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + vs-code: + ansible_host: 192.168.0.16 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + gitea-server: + ansible_host: 192.168.0.39 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: [] + ai-host: + ansible_host: 192.168.0.50 + ansible_become_password: "{{ ansible_become_passwd }}" + services_to_run: + - coder_ai diff --git a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml index 285afd2..b6dad60 100644 --- a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml +++ b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml @@ -25,6 +25,10 @@ prompt: "IP address for the container (in x.x.x.x/x formant)" private: false + - name: lxc_is_privileged + prompt: "Unprivileged LXC (true/false)?" + private: false + pre_tasks: - name: Validate hostname ansible.builtin.fail: diff --git a/playbooks/maintain.yaml b/playbooks/maintain.yaml index d15c438..9270457 100644 --- a/playbooks/maintain.yaml +++ b/playbooks/maintain.yaml @@ -1,6 +1,6 @@ --- - name: Deploy and set up an LXC container in Proxmox - hosts: all + hosts: virtual remote_user: ansible vars_files: @@ -18,3 +18,5 @@ - ../roles/harden_ssh # Update configs - omz, nvim, ranger and so on. Distribute the last version of those configs - ../roles/update_configs + # Make sure that the services that are supposed to run are running + - ../roles/check_services diff --git a/roles/check_services/tasks/main.yaml b/roles/check_services/tasks/main.yaml new file mode 100644 index 0000000..0161cae --- /dev/null +++ b/roles/check_services/tasks/main.yaml @@ -0,0 +1,7 @@ +--- + +- name: Make sure required services are running + ansible.builtin.service: + name: "{{ item }}" + state: started + loop: "{{ services_to_run }}" diff --git a/roles/common_healthcheck/tasks/main.yaml b/roles/common_healthcheck/tasks/main.yaml index c024da8..bf2d491 100644 --- a/roles/common_healthcheck/tasks/main.yaml +++ b/roles/common_healthcheck/tasks/main.yaml @@ -23,8 +23,8 @@ become: false # We have to use this complicated pipeline because of Alpine and its wierd df implementation ansible.builtin.shell: set -o pipefail && df -h / | tail -1 | awk '{gsub(/%/, "", $5); print $5}' - register: free_disk_space_result - failed_when: free_disk_space_result.stdout | int > 85 + register: common_healthcheck_space_left_result + failed_when: common_healthcheck_space_left_result.stdout | int > 85 changed_when: false # This task does not change the system rescue: @@ -41,5 +41,9 @@ body: - "{{ ansible_facts['hostname'] }}: Disk space is low" delegate_to: 127.0.0.1 - failed_when: false + failed_when: false # It's OK if it fails, not critical changed_when: false # This task does not change the system + + - name: Resize rootfs if it's an LXC + ansible.builtin.include_tasks: resize_lxc_rootfs.yaml + when: ansible_virtualization_type == 'lxc' diff --git a/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml b/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml new file mode 100644 index 0000000..754682a --- /dev/null +++ b/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml @@ -0,0 +1,24 @@ +--- +- name: Get container info by name + delegate_to: localhost + become: false + community.general.proxmox_vm_info: + validate_certs: false + node: proxmox-server + api_user: root@pam + api_host: 192.168.0.2 + api_token_id: ansible + api_token_secret: "{{ proxmox_token_secret }}" + + name: "{{ inventory_hostname }}" + type: lxc + register: common_healthcheck_vmid + +- name: Resize LXC's rootfs + become: true + ansible.builtin.command: + cmd: pct resize {{ common_healthcheck_vmid.proxmox_vms[0].vmid }} rootfs +5G + delegate_to: 192.168.0.2 + changed_when: true + vars: + ansible_become_password: "{{ ansible_become_passwd }}" diff --git a/roles/deploy_lxc_on_proxmox/tasks/main.yaml b/roles/deploy_lxc_on_proxmox/tasks/main.yaml index 6a74105..b396bd4 100644 --- a/roles/deploy_lxc_on_proxmox/tasks/main.yaml +++ b/roles/deploy_lxc_on_proxmox/tasks/main.yaml @@ -6,7 +6,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" @@ -14,6 +14,7 @@ password: "{{ lxc_root_password }}" hostname: "{{ lxc_hostname }}" ostemplate: 'main:vztmpl/debian-13-golden-image.tar.gz' + unprivileged: "{{ lxc_is_privileged }}" memory: 2048 cores: 2 state: present @@ -33,7 +34,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" diff --git a/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml b/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml index 52bbc27..2d2d266 100644 --- a/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml +++ b/roles/deploy_vm_on_proxmox/tasks/create_vm.yaml @@ -6,7 +6,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" @@ -29,7 +29,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" @@ -49,7 +49,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" @@ -64,10 +64,9 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" name: "{{ vm_hostname }}" state: started - diff --git a/roles/deploy_vm_on_proxmox/tasks/main.yaml b/roles/deploy_vm_on_proxmox/tasks/main.yaml index 07f5a53..d54ec6d 100644 --- a/roles/deploy_vm_on_proxmox/tasks/main.yaml +++ b/roles/deploy_vm_on_proxmox/tasks/main.yaml @@ -5,7 +5,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" diff --git a/roles/deploy_vm_on_proxmox/tasks/start_vm.yaml b/roles/deploy_vm_on_proxmox/tasks/start_vm.yaml index 455bf6f..8140a72 100644 --- a/roles/deploy_vm_on_proxmox/tasks/start_vm.yaml +++ b/roles/deploy_vm_on_proxmox/tasks/start_vm.yaml @@ -6,7 +6,7 @@ validate_certs: false node: proxmox-server api_user: root@pam - api_host: 192.168.0.2 + api_host: "{{ proxmox_1_host }}" api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" @@ -19,4 +19,3 @@ timeout: 120 delegate_to: localhost changed_when: false -