From f29de423973a918a231bf2cb265a031d3ce4eff6 Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Thu, 17 Sep 2026 11:16:18 +0400 Subject: [PATCH] feat(pb,role,task): generalize names of common pre_tasks and their variables, specifies LXC-specific ones --- playbooks/deploy_and_set_up_lxc_on_proxmox.yaml | 10 +++++----- roles/deploy_lxc_on_proxmox/tasks/main.yaml | 6 +++--- tasks/hostname_validation.yaml | 4 ++-- tasks/human_admin_user_validation.yaml | 4 ++-- tasks/ip_validation.yaml | 8 ++++---- ...lidation.yaml => lxc_root_password_validation.yaml} | 0 6 files changed, 16 insertions(+), 16 deletions(-) rename tasks/{password_validation.yaml => lxc_root_password_validation.yaml} (100%) diff --git a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml index 28011a1..40d8c51 100644 --- a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml +++ b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml @@ -14,8 +14,8 @@ - name: Include input and validation for hostname ansible.builtin.include_tasks: ../tasks/hostname_validation.yaml - - name: Include input and validation for password - ansible.builtin.include_tasks: ../tasks/password_validation.yaml + - name: Include input and validation for LXC root password + ansible.builtin.include_tasks: ../tasks/lxc_root_password_validation.yaml - name: Include input and validation for IP ansible.builtin.include_tasks: ../tasks/ip_validation.yaml @@ -33,7 +33,7 @@ tasks: - name: Add the target host to the inventory ansible.builtin.add_host: - name: "{{ lxc_ip_address }}" + name: "{{ guest_ip_address }}" groups: new_host ansible_user: ansible ansible_become_password: "{{ ansible_become_passwd }}" @@ -58,10 +58,10 @@ - name: Include human admin user role ansible.builtin.include_role: name: ../roles/human_admin_user - when: "hostvars['localhost']['lxc_human_admin_user'] | bool" + when: "hostvars['localhost']['create_human_admin_user'] | bool" - name: Include update configs role ansible.builtin.include_role: name: ../roles/update_configs - when: "hostvars['localhost']['lxc_human_admin_user'] | bool" + when: "hostvars['localhost']['create_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 e513c6a..d3e6261 100644 --- a/roles/deploy_lxc_on_proxmox/tasks/main.yaml +++ b/roles/deploy_lxc_on_proxmox/tasks/main.yaml @@ -12,7 +12,7 @@ cmode: "shell" password: "{{ lxc_root_password }}" - hostname: "{{ lxc_hostname }}" + hostname: "{{ guest_hostname }}" ostemplate: 'main:vztmpl/debian-13-golden-image.tar.gz' unprivileged: "{{ lxc_privileged }}" memory: 2048 @@ -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 }}/{{ lxc_netmask }},bridge=vmbr0" + net0: "name=eth0,gw=192.168.0.1,ip={{ guest_ip_address }}/{{ guest_netmask }},bridge=vmbr0" - name: Make sure the container has started become: false @@ -38,7 +38,7 @@ api_token_id: ansible api_token_secret: "{{ proxmox_token_secret }}" - hostname: "{{ lxc_hostname }}" + hostname: "{{ guest_hostname }}" state: started retries: 3 delay: 15 diff --git a/tasks/hostname_validation.yaml b/tasks/hostname_validation.yaml index 7ff704c..252ce87 100644 --- a/tasks/hostname_validation.yaml +++ b/tasks/hostname_validation.yaml @@ -2,7 +2,7 @@ - name: Set default hostname ansible.builtin.set_fact: - lxc_hostname: "new-lxc-test" + guest_hostname: "new-lxc-test" - name: Prompt for hostname with immediate validation ansible.builtin.pause: @@ -19,5 +19,5 @@ - name: Use user input only if provided, otherwise keep the default ansible.builtin.set_fact: - lxc_hostname: "{{ hostname_result.user_input }}" + guest_hostname: "{{ hostname_result.user_input }}" when: hostname_result.user_input | length > 0 diff --git a/tasks/human_admin_user_validation.yaml b/tasks/human_admin_user_validation.yaml index df6d04b..849ba7b 100644 --- a/tasks/human_admin_user_validation.yaml +++ b/tasks/human_admin_user_validation.yaml @@ -2,7 +2,7 @@ - name: Set default human admin user ansible.builtin.set_fact: - lxc_human_admin_user: true + create_human_admin_user: true - name: Prompt for human admin user creation with immediate validation ansible.builtin.pause: @@ -18,5 +18,5 @@ - name: Use user input only if provided, otherwise keep the default ansible.builtin.set_fact: - lxc_human_admin_user: "{{ human_admin_user_result.user_input }}" + create_human_admin_user: "{{ human_admin_user_result.user_input }}" when: human_admin_user_result.user_input | length > 0 diff --git a/tasks/ip_validation.yaml b/tasks/ip_validation.yaml index a3cf44d..eabcd78 100644 --- a/tasks/ip_validation.yaml +++ b/tasks/ip_validation.yaml @@ -2,11 +2,11 @@ - name: Set default ip ansible.builtin.set_fact: - lxc_ip_address: "192.168.0.90" + guest_ip_address: "192.168.0.90" - name: Set default network mask ansible.builtin.set_fact: - lxc_netmask: "24" + guest_netmask: "24" - name: Prompt for IP with immediate validation ansible.builtin.pause: @@ -20,10 +20,10 @@ - name: Use user input only if provided, otherwise keep the default (IP) ansible.builtin.set_fact: - lxc_ip_address: "{{ ip_result.user_input.split('/') | first }}" + guest_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 }}" + guest_netmask: "{{ ip_result.user_input.split('/') | second }}" when: ip_result.user_input | length > 0 diff --git a/tasks/password_validation.yaml b/tasks/lxc_root_password_validation.yaml similarity index 100% rename from tasks/password_validation.yaml rename to tasks/lxc_root_password_validation.yaml