From daa582657340c45faa7d61109c62eb61dbe86142 Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Thu, 17 Sep 2026 10:50:46 +0400 Subject: [PATCH] feat(pb,role,task): completes the LXC deployment workflow using new validation tasks --- playbooks/deploy_and_set_up_lxc_on_proxmox.yaml | 14 +++----------- roles/deploy_lxc_on_proxmox/tasks/main.yaml | 4 ++-- tasks/ip_validation.yaml | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml index d264115..28011a1 100644 --- a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml +++ b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml @@ -31,17 +31,9 @@ - ../roles/deploy_lxc_on_proxmox tasks: - - name: Make the prompted IP available to the whole playbook - ansible.builtin.set_fact: - fact_lxc_ip_address: "{{ lxc_ip_address.split('/') | first }}" - - - name: Make the "human admin user" selection available to the whole playbook - ansible.builtin.set_fact: - fact_lxc_create_human_admin_user: "{{ lxc_create_human_admin_user }}" - - name: Add the target host to the inventory ansible.builtin.add_host: - name: "{{ fact_lxc_ip_address }}" + name: "{{ lxc_ip_address }}" groups: new_host ansible_user: ansible ansible_become_password: "{{ ansible_become_passwd }}" @@ -66,10 +58,10 @@ - name: Include human admin user role ansible.builtin.include_role: name: ../roles/human_admin_user - when: "hostvars['localhost']['fact_lxc_create_human_admin_user'] | bool" + when: "hostvars['localhost']['lxc_human_admin_user'] | bool" - name: Include update configs role ansible.builtin.include_role: name: ../roles/update_configs - when: "hostvars['localhost']['fact_lxc_create_human_admin_user'] | bool" + when: "hostvars['localhost']['lxc_human_admin_user'] | bool" diff --git a/roles/deploy_lxc_on_proxmox/tasks/main.yaml b/roles/deploy_lxc_on_proxmox/tasks/main.yaml index b396bd4..e513c6a 100644 --- a/roles/deploy_lxc_on_proxmox/tasks/main.yaml +++ b/roles/deploy_lxc_on_proxmox/tasks/main.yaml @@ -14,7 +14,7 @@ password: "{{ lxc_root_password }}" hostname: "{{ lxc_hostname }}" ostemplate: 'main:vztmpl/debian-13-golden-image.tar.gz' - unprivileged: "{{ lxc_is_privileged }}" + unprivileged: "{{ lxc_privileged }}" memory: 2048 cores: 2 state: present @@ -26,7 +26,7 @@ storage: local pubkey: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/ansible_key.pub') }}" netif: - net0: "name=eth0,gw=192.168.0.1,ip={{ lxc_ip_address }},bridge=vmbr0" + net0: "name=eth0,gw=192.168.0.1,ip={{ lxc_ip_address }}/{{ lxc_netmask }},bridge=vmbr0" - name: Make sure the container has started become: false diff --git a/tasks/ip_validation.yaml b/tasks/ip_validation.yaml index bbbd866..a3cf44d 100644 --- a/tasks/ip_validation.yaml +++ b/tasks/ip_validation.yaml @@ -2,7 +2,11 @@ - name: Set default ip ansible.builtin.set_fact: - lxc_ip_address: "192.168.0.90/24" + lxc_ip_address: "192.168.0.90" + +- name: Set default network mask + ansible.builtin.set_fact: + lxc_netmask: "24" - name: Prompt for IP with immediate validation ansible.builtin.pause: @@ -14,7 +18,12 @@ retries: 2 delay: 0 -- name: Use user input only if provided, otherwise keep the default +- name: Use user input only if provided, otherwise keep the default (IP) ansible.builtin.set_fact: - lxc_ip_address: "{{ ip_result.user_input }}" + lxc_ip_address: "{{ ip_result.user_input.split('/') | first }}" + when: ip_result.user_input | length > 0 + +- name: Use user input only if provided, otherwise keep the default (netmask) + ansible.builtin.set_fact: + lxc_netmask: "{{ ip_result.user_input.split('/') | second }}" when: ip_result.user_input | length > 0