Compare commits
2 Commits
4789bbd850
...
daa5826573
| Author | SHA1 | Date | |
|---|---|---|---|
| daa5826573 | |||
| 0696218eb6 |
@@ -10,76 +10,30 @@
|
||||
ansible_user_passwd_hash: "{{ ansible_password | password_hash('sha512', 's3edscrj45e6r') }}"
|
||||
user_passwd_hash: "{{ user_password | password_hash('sha512', 's3ed6123jhgcr') }}"
|
||||
|
||||
vars_prompt:
|
||||
- name: lxc_hostname
|
||||
prompt: "Hostname for the container (may only contain letters (a-z, A-Z), numbers (0-9), and hyphens)"
|
||||
default: "new-lxc-test"
|
||||
private: false
|
||||
|
||||
- name: lxc_root_password
|
||||
prompt: "Root password"
|
||||
default: "new-lxc-test"
|
||||
private: true
|
||||
confirm: true
|
||||
encrypt: sha512_crypt
|
||||
|
||||
- name: lxc_ip_address
|
||||
prompt: "IP address for the container (in x.x.x.x/x formant)"
|
||||
default: "192.168.0.90/24"
|
||||
private: false
|
||||
|
||||
- name: lxc_is_privileged
|
||||
prompt: "Unprivileged LXC (true/false)?"
|
||||
default: true
|
||||
private: false
|
||||
|
||||
- name: lxc_create_human_admin_user
|
||||
prompt: "Create human admin user? (true/false)?"
|
||||
default: true
|
||||
private: false
|
||||
|
||||
pre_tasks:
|
||||
- name: Validate hostname
|
||||
ansible.builtin.fail:
|
||||
msg: |
|
||||
Invalid hostname: "{{ lxc_hostname }}"
|
||||
Hostname must:
|
||||
- contain only letters (a-z, A-Z), digits (0-9), hyphens (-), and dots (.)
|
||||
- not start or end with a hyphen or dot
|
||||
- have each label between 1 and 63 characters
|
||||
- not exceed 253 characters in total
|
||||
when: >
|
||||
lxc_hostname | length > 253 or
|
||||
lxc_hostname is not regex('^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
|
||||
run_once: true
|
||||
- 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 IP
|
||||
ansible.builtin.include_tasks: ../tasks/ip_validation.yaml
|
||||
|
||||
- name: Include input and validation for LXC privilege
|
||||
ansible.builtin.include_tasks: ../tasks/lxc_privileged_validation.yaml
|
||||
|
||||
- name: Include input and validation for human admin user creation
|
||||
ansible.builtin.include_tasks: ../tasks/human_admin_user_validation.yaml
|
||||
|
||||
- name: Validate IP address
|
||||
ansible.builtin.fail:
|
||||
msg: |
|
||||
Invalid IP address: "{{ lxc_ip_address }}"
|
||||
IP address must be in x.x.x.x/x format (e.g., 192.168.0.90/24).
|
||||
when: not lxc_ip_address is regex('^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)(\\/(3[0-2]|[12]?\\d))?$')
|
||||
run_once: true
|
||||
|
||||
roles:
|
||||
- ../roles/deploy_lxc_on_proxmox
|
||||
|
||||
tasks:
|
||||
- name: Make the prompted hostname available to the whole playbook
|
||||
ansible.builtin.set_fact:
|
||||
fact_lxc_hostname: "{{ lxc_hostname }}"
|
||||
|
||||
- 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 }}"
|
||||
@@ -104,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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: Set default hostname
|
||||
ansible.builtin.set_fact:
|
||||
lxc_hostname: "new-lxc-test"
|
||||
|
||||
- name: Prompt for hostname with immediate validation
|
||||
ansible.builtin.pause:
|
||||
prompt: "Enter hostname (letters, digits, hyphens, dots; max 253 chars) [new-lxc-test]"
|
||||
register: hostname_result
|
||||
until: >
|
||||
hostname_result.user_input | length == 0 or
|
||||
(
|
||||
hostname_result.user_input | length <= 253 and
|
||||
hostname_result.user_input is regex('^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
|
||||
)
|
||||
retries: 2
|
||||
delay: 0
|
||||
|
||||
- name: Use user input only if provided, otherwise keep the default
|
||||
ansible.builtin.set_fact:
|
||||
lxc_hostname: "{{ hostname_result.user_input }}"
|
||||
when: hostname_result.user_input | length > 0
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
|
||||
- name: Set default human admin user
|
||||
ansible.builtin.set_fact:
|
||||
lxc_human_admin_user: true
|
||||
|
||||
- name: Prompt for human admin user creation with immediate validation
|
||||
ansible.builtin.pause:
|
||||
prompt: "Create human admin user? (true/false) [true]"
|
||||
register: human_admin_user_result
|
||||
until: >
|
||||
human_admin_user_result.user_input | length == 0 or
|
||||
(
|
||||
human_admin_user_result.user_input in ['true', 'false']
|
||||
)
|
||||
retries: 2
|
||||
delay: 0
|
||||
|
||||
- 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 }}"
|
||||
when: human_admin_user_result.user_input | length > 0
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
|
||||
- name: Set default ip
|
||||
ansible.builtin.set_fact:
|
||||
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:
|
||||
prompt: "Enter ip in x.x.x.x/x format [192.168.0.90/24]"
|
||||
register: ip_result
|
||||
until: >
|
||||
ip_result.user_input | length == 0 or
|
||||
ip_result.user_input is regex('^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)/(3[0-2]|[12]?\\d)$')
|
||||
retries: 2
|
||||
delay: 0
|
||||
|
||||
- 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 }}"
|
||||
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
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
|
||||
- name: Set default privileged
|
||||
ansible.builtin.set_fact:
|
||||
lxc_privileged: false
|
||||
|
||||
- name: Prompt for privileged with immediate validation
|
||||
ansible.builtin.pause:
|
||||
prompt: "Privileged LXC? (true/false) [false]"
|
||||
register: privileged_result
|
||||
until: >
|
||||
privileged_result.user_input | length == 0 or
|
||||
(
|
||||
privileged_result.user_input in ['true', 'false']
|
||||
)
|
||||
retries: 2
|
||||
delay: 0
|
||||
|
||||
- name: Use user input only if provided, otherwise keep the default
|
||||
ansible.builtin.set_fact:
|
||||
lxc_privileged: "{{ privileged_result.user_input }}"
|
||||
when: privileged_result.user_input | length > 0
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
|
||||
- name: Set default password
|
||||
ansible.builtin.set_fact:
|
||||
lxc_root_password: "new-lxc-test"
|
||||
|
||||
- name: Prompt for password
|
||||
ansible.builtin.pause:
|
||||
prompt: "Enter password (letters, digits, hyphens, dots; max 253 chars) [new-lxc-test]"
|
||||
echo: false
|
||||
register: password_result_1
|
||||
until: >
|
||||
password_result_1.user_input | length == 0 or
|
||||
(
|
||||
password_result_1.user_input | length <= 253 and
|
||||
password_result_1.user_input is regex('^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
|
||||
)
|
||||
retries: 3
|
||||
delay: 0
|
||||
|
||||
- name: Prompt for password (confirmation)
|
||||
ansible.builtin.pause:
|
||||
prompt: "Confirm your new password"
|
||||
echo: no
|
||||
register: password_result_2
|
||||
|
||||
- name: Ensure passwords match
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- password_result_1.user_input == password_result_2.user_input
|
||||
fail_msg: "Passwords do not match!"
|
||||
success_msg: "Password confirmed."
|
||||
|
||||
- name: Use user input only if provided, otherwise keep the default
|
||||
ansible.builtin.set_fact:
|
||||
lxc_root_password: "{{ password_result_1.user_input }}"
|
||||
when: password_result_1.user_input | length > 0
|
||||
|
||||
Reference in New Issue
Block a user