Compare commits
4 Commits
4f09e886c2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e3ab88304 | |||
| d5cf6f656e | |||
| 8a9903eb4c | |||
| 3b6f59a029 |
@@ -144,26 +144,17 @@ The role includes idempotency checking. If a container with the specified `lxc_v
|
|||||||
|
|
||||||
### Using Standalone Tasks
|
### Using Standalone Tasks
|
||||||
|
|
||||||
When using individual task files via `tasks_from`, you must set `module_defaults` at the play level since the tasks bypass the role's main entry point:
|
Individual task files (`stop`, `start`, `delete`, `convert`, etc.) can be invoked via `tasks_from` directly — each task file wraps its work in a block with the role's shared `module_defaults`, so the Proxmox API connection is configured automatically as long as the `proxmox_*` connection variables are in scope (typically from `group_vars/all/`).
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Convert container to a template
|
- name: Convert container to a template
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
module_defaults:
|
|
||||||
community.proxmox.proxmox:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_port: "{{ proxmox_api_port }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
validate_certs: "{{ proxmox_api_validate_certs }}"
|
|
||||||
node: "{{ proxmox_node }}"
|
|
||||||
vars:
|
|
||||||
lxc_hostname: "{{ lxc_hostname }}"
|
|
||||||
tasks:
|
tasks:
|
||||||
- include_role:
|
- include_role:
|
||||||
name: proxmox_lxc_provision
|
name: proxmox_lxc_provision
|
||||||
tasks_from: convert
|
tasks_from: convert
|
||||||
|
vars:
|
||||||
|
lxc_hostname: my-container
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating an LXC Container and Converting it to a Template
|
### Creating an LXC Container and Converting it to a Template
|
||||||
@@ -185,19 +176,10 @@ When using individual task files via `tasks_from`, you must set `module_defaults
|
|||||||
|
|
||||||
- name: Convert the created container to a template
|
- name: Convert the created container to a template
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
module_defaults:
|
|
||||||
community.proxmox.proxmox:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_port: "{{ proxmox_api_port }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
validate_certs: "{{ proxmox_api_validate_certs }}"
|
|
||||||
node: "{{ proxmox_node }}"
|
|
||||||
vars:
|
|
||||||
lxc_hostname: "{{ lxc_hostname }}"
|
|
||||||
tasks:
|
tasks:
|
||||||
- include_role:
|
- include_role:
|
||||||
name: proxmox_lxc_provision
|
name: proxmox_lxc_provision
|
||||||
tasks_from: convert
|
tasks_from: convert
|
||||||
|
vars:
|
||||||
|
lxc_hostname: "{{ lxc_hostname }}"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ proxmox_api_validate_certs: false
|
|||||||
# Host to delegate pct commands to (use inventory hostname for become_password to work)
|
# Host to delegate pct commands to (use inventory hostname for become_password to work)
|
||||||
proxmox_delegate_host: "{{ proxmox_api_host }}"
|
proxmox_delegate_host: "{{ proxmox_api_host }}"
|
||||||
|
|
||||||
|
# Shared Proxmox API args referenced by each task file's module_defaults block.
|
||||||
|
# Override the underlying proxmox_* vars (e.g. from group_vars/all/) to customize.
|
||||||
|
_proxmox_api_args:
|
||||||
|
api_host: "{{ proxmox_api_host }}"
|
||||||
|
api_port: "{{ proxmox_api_port }}"
|
||||||
|
api_user: "{{ proxmox_api_user }}"
|
||||||
|
api_token_id: "{{ proxmox_api_token_id }}"
|
||||||
|
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||||
|
validate_certs: "{{ proxmox_api_validate_certs }}"
|
||||||
|
node: "{{ proxmox_node }}"
|
||||||
|
|
||||||
# LXC defaults
|
# LXC defaults
|
||||||
lxc_template: "local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst"
|
lxc_template: "local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst"
|
||||||
lxc_cores: 4
|
lxc_cores: 4
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Check if LXC exists
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Query Proxmox for existing LXCs
|
- name: Query Proxmox for existing LXCs
|
||||||
community.proxmox.proxmox_vm_info:
|
community.proxmox.proxmox_vm_info:
|
||||||
type: lxc
|
type: lxc
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Clone LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Create a full clone of the container
|
- name: Create a full clone of the container
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
vmid: "{{ lxc_vmid | default(0) }}"
|
vmid: "{{ lxc_vmid | default(0) }}"
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Convert LXC container to template
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- ansible.builtin.include_tasks: stop.yml
|
- ansible.builtin.include_tasks: stop.yml
|
||||||
|
|
||||||
- name: Convert container to template
|
- name: Convert container to template
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Create LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Create an LXC container
|
- name: Create an LXC container
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
vmid: "{{ lxc_vmid | default(omit) }}"
|
vmid: "{{ lxc_vmid | default(omit) }}"
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Delete LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- ansible.builtin.include_tasks: stop.yml
|
- ansible.builtin.include_tasks: stop.yml
|
||||||
|
|
||||||
- name: Delete a container
|
- name: Delete a container
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
---
|
---
|
||||||
- name: Proxmox LXC provision
|
|
||||||
module_defaults:
|
|
||||||
community.proxmox.proxmox: &proxmox_defaults
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_port: "{{ proxmox_api_port }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
validate_certs: "{{ proxmox_api_validate_certs }}"
|
|
||||||
node: "{{ proxmox_node }}"
|
|
||||||
community.proxmox.proxmox_vm_info: *proxmox_defaults
|
|
||||||
block:
|
|
||||||
- name: Check if container exists
|
- name: Check if container exists
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: check-exists.yml
|
file: check-exists.yml
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
name: root
|
name: root
|
||||||
password: "{{ lxc_root_password | password_hash('sha512') }}"
|
password: "{{ lxc_root_password | password_hash('sha512') }}"
|
||||||
update_password: always
|
update_password: always
|
||||||
|
become: true
|
||||||
when: lxc_root_password is defined
|
when: lxc_root_password is defined
|
||||||
|
|
||||||
- name: Change user password
|
- name: Change user password
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
name: "{{ lxc_user_name }}"
|
name: "{{ lxc_user_name }}"
|
||||||
password: "{{ lxc_user_password | password_hash('sha512') }}"
|
password: "{{ lxc_user_password | password_hash('sha512') }}"
|
||||||
update_password: always
|
update_password: always
|
||||||
|
become: true
|
||||||
when: lxc_user_password is defined
|
when: lxc_user_password is defined
|
||||||
|
|
||||||
- name: Regenerate SSH host keys
|
- name: Regenerate SSH host keys
|
||||||
@@ -18,7 +20,7 @@
|
|||||||
name: system_setup
|
name: system_setup
|
||||||
tasks_from: ssh
|
tasks_from: ssh
|
||||||
vars:
|
vars:
|
||||||
regenerate_ssh_keys: true
|
regenerate_ssh_host_keys: true
|
||||||
|
|
||||||
- name: Remove previous entry from known hosts
|
- name: Remove previous entry from known hosts
|
||||||
ansible.builtin.known_hosts:
|
ansible.builtin.known_hosts:
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Start LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Start the LXC container
|
- name: Start the LXC container
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
vmid: "{{ lxc_result.vmid }}"
|
vmid: "{{ lxc_result.vmid }}"
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Stop LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Stop container if it is running
|
- name: Stop container if it is running
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
vmid: "{{ lxc_vmid | default(omit) }}"
|
vmid: "{{ lxc_vmid | default(omit) }}"
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
- name: Update LXC container
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
||||||
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
||||||
|
block:
|
||||||
- name: Update an LXC container
|
- name: Update an LXC container
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
vmid: "{{ lxc_vmid }}"
|
vmid: "{{ lxc_vmid }}"
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
name: system_maintenance
|
name: system_maintenance
|
||||||
|
|
||||||
# Install extra packages
|
# Install extra packages
|
||||||
- include_tasks: extra-packages.yaml
|
- include_tasks: extra-packages.yml
|
||||||
|
|
||||||
# Create a user admin account
|
# Create a user admin account
|
||||||
- include_tasks: user.yaml
|
- include_tasks: user.yml
|
||||||
|
|
||||||
# Harden SSH configuration
|
# Harden SSH configuration
|
||||||
- include_tasks: ssh.yaml
|
- include_tasks: ssh.yml
|
||||||
Reference in New Issue
Block a user