You've already forked role_proxmox
Compare commits
3 Commits
main
...
47345a9c95
| Author | SHA1 | Date | |
|---|---|---|---|
| 47345a9c95 | |||
| c0e0bc169e | |||
| 0d467d737d |
@@ -74,23 +74,6 @@ proxmox_instance_cloudinit_nameservers: ""
|
|||||||
proxmox_instance_cloudinit_searchdomains: null
|
proxmox_instance_cloudinit_searchdomains: null
|
||||||
proxmox_instance_cloudinit_sshkeys: ""
|
proxmox_instance_cloudinit_sshkeys: ""
|
||||||
|
|
||||||
# Proxmox VE instance (CT)
|
|
||||||
proxmox_instance_cmode: tty
|
|
||||||
proxmox_instance_disk_volumes: {}
|
|
||||||
# Example:
|
|
||||||
# storage: truenas-nfs
|
|
||||||
# size: 5G
|
|
||||||
proxmox_instance_features: []
|
|
||||||
proxmox_instance_mount_volumes: []
|
|
||||||
proxmox_instance_netif: {}
|
|
||||||
proxmox_instance_ostemplate: ""
|
|
||||||
proxmox_instance_ostype: auto
|
|
||||||
proxmox_instance_password: ""
|
|
||||||
proxmox_instance_startup: ""
|
|
||||||
proxmox_instance_swap: 0
|
|
||||||
proxmox_instance_timeout: 600
|
|
||||||
proxmox_instance_unprivileged: true
|
|
||||||
|
|
||||||
## HA configuration
|
## HA configuration
|
||||||
proxmox_instance_ha:
|
proxmox_instance_ha:
|
||||||
max_restart: 3
|
max_restart: 3
|
||||||
|
|||||||
@@ -59,46 +59,3 @@
|
|||||||
retries: 100
|
retries: 100
|
||||||
delay: 36
|
delay: 36
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Disable maintenance mode on node
|
|
||||||
ansible.builtin.command:
|
|
||||||
argv:
|
|
||||||
- ha-manager
|
|
||||||
- crm-command
|
|
||||||
- node-maintenance
|
|
||||||
- disable
|
|
||||||
- "{{ inventory_hostname_short }}"
|
|
||||||
become: true
|
|
||||||
register: proxmox_maintenance_disabled
|
|
||||||
changed_when: proxmox_maintenance_disabled.rc == 0
|
|
||||||
listen: Disable maintenance mode
|
|
||||||
|
|
||||||
- name: Wait for the instances to return to the current host
|
|
||||||
community.proxmox.proxmox_vm_info:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
node: "{{ inventory_hostname_short }}"
|
|
||||||
type: all
|
|
||||||
validate_certs: "{{ proxmox_api_validate_certs }}"
|
|
||||||
become: true
|
|
||||||
register: proxmox_current_instances
|
|
||||||
retries: 20
|
|
||||||
delay: 30
|
|
||||||
until: current == expected
|
|
||||||
vars:
|
|
||||||
current: "{{ proxmox_current_instances.proxmox_vms | map(attribute='name') | sort }}"
|
|
||||||
expected: "{{ proxmox_node_instances.proxmox_vms | map(attribute='name') | sort }}"
|
|
||||||
listen: Disable maintenance mode
|
|
||||||
|
|
||||||
- name: Restart instance
|
|
||||||
community.proxmox.proxmox:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
vmid: "{{ proxmox_instance_vmid }}"
|
|
||||||
node: "{{ proxmox_instance_node }}"
|
|
||||||
state: restarted
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
---
|
|
||||||
# tasks file for proxmox
|
|
||||||
|
|
||||||
- name: Get instance configuration file informations
|
|
||||||
ansible.builtin.stat:
|
|
||||||
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
|
|
||||||
become: true
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
register: proxmox_ct_configuration
|
|
||||||
|
|
||||||
- name: Manage instance
|
|
||||||
community.proxmox.proxmox:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
cores: "{{ proxmox_instance_cores }}"
|
|
||||||
disk_volume: "{{ proxmox_instance_disk_volumes }}"
|
|
||||||
features: "{{ proxmox_instance_features if proxmox_ct_configuration.stat.exists else omit }}"
|
|
||||||
hostname: "{{ inventory_hostname }}"
|
|
||||||
memory: "{{ proxmox_instance_memory }}"
|
|
||||||
mount_volumes: "{{ proxmox_instance_mount_volumes }}"
|
|
||||||
netif: "{{ proxmox_instance_netif }}"
|
|
||||||
node: "{{ proxmox_instance_node }}"
|
|
||||||
ostemplate: "{{ proxmox_instance_ostemplate }}"
|
|
||||||
ostype: "{{ proxmox_instance_ostype }}"
|
|
||||||
password: "{{ omit if proxmox_instance_password | length == 0 else proxmox_instance_password }}"
|
|
||||||
startup: "{{ omit if proxmox_instance_startup | length == 0 else proxmox_instance_startup }}"
|
|
||||||
swap: "{{ proxmox_instance_swap }}"
|
|
||||||
timeout: "{{ proxmox_instance_timeout }}"
|
|
||||||
unprivileged: "{{ (proxmox_instance_unprivileged | int) if proxmox_ct_configuration.stat.exists else omit }}"
|
|
||||||
update: true
|
|
||||||
vmid: "{{ proxmox_instance_vmid }}"
|
|
||||||
become: true
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
notify: Restart instance
|
|
||||||
|
|
||||||
- name: Ensure instance is started
|
|
||||||
community.proxmox.proxmox:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
vmid: "{{ proxmox_instance_vmid }}"
|
|
||||||
node: "{{ proxmox_instance_node }}"
|
|
||||||
state: started
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
|
|
||||||
- name: Manage cmode option
|
|
||||||
ansible.builtin.lineinfile:
|
|
||||||
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
|
|
||||||
regexp: '^cmode:'
|
|
||||||
line: "cmode: {{ proxmox_instance_cmode }}"
|
|
||||||
become: true
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
notify: Restart instance
|
|
||||||
|
|
||||||
- name: Manage features option
|
|
||||||
ansible.builtin.lineinfile:
|
|
||||||
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
|
|
||||||
regexp: '^features:'
|
|
||||||
line: "features: {{ proxmox_instance_features | join(' ') }}"
|
|
||||||
become: true
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
notify: Restart instance
|
|
||||||
|
|
||||||
- name: Manage unprivileged option
|
|
||||||
ansible.builtin.lineinfile:
|
|
||||||
path: /etc/pve/lxc/{{ proxmox_instance_vmid }}.conf
|
|
||||||
regexp: '^unprivileged:'
|
|
||||||
line: "unprivileged: {{ proxmox_instance_unprivileged | int }}"
|
|
||||||
become: true
|
|
||||||
delegate_to: "{{ proxmox_delegate_to }}"
|
|
||||||
notify: Restart instance
|
|
||||||
|
|
||||||
- name: Flush handlers
|
|
||||||
ansible.builtin.meta: flush_handlers
|
|
||||||
@@ -24,9 +24,3 @@
|
|||||||
when:
|
when:
|
||||||
- proxmox_instance_type == "vm"
|
- proxmox_instance_type == "vm"
|
||||||
- proxmox_instance_ha | length > 0
|
- proxmox_instance_ha | length > 0
|
||||||
|
|
||||||
# Instance: ct
|
|
||||||
- name: Import instance creation tasks
|
|
||||||
ansible.builtin.include_tasks:
|
|
||||||
file: instance_ct.yml
|
|
||||||
when: proxmox_instance_type == "ct"
|
|
||||||
|
|||||||
@@ -17,18 +17,6 @@
|
|||||||
- name: Upgrade tasks
|
- name: Upgrade tasks
|
||||||
when: apt_upgradable.stdout_lines | length > 1
|
when: apt_upgradable.stdout_lines | length > 1
|
||||||
block:
|
block:
|
||||||
- name: List instance on the current node
|
|
||||||
community.proxmox.proxmox_vm_info:
|
|
||||||
api_host: "{{ proxmox_api_host }}"
|
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
|
||||||
api_user: "{{ proxmox_api_user }}"
|
|
||||||
node: "{{ inventory_hostname_short }}"
|
|
||||||
type: all
|
|
||||||
validate_certs: "{{ proxmox_api_validate_certs }}"
|
|
||||||
become: true
|
|
||||||
register: proxmox_node_instances
|
|
||||||
|
|
||||||
- name: Enable maintenance node
|
- name: Enable maintenance node
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
@@ -40,7 +28,6 @@
|
|||||||
become: true
|
become: true
|
||||||
register: proxmox_maintenance_enabled
|
register: proxmox_maintenance_enabled
|
||||||
changed_when: proxmox_maintenance_enabled.rc == 0
|
changed_when: proxmox_maintenance_enabled.rc == 0
|
||||||
notify: Disable maintenance mode
|
|
||||||
|
|
||||||
- name: Wait for the instances to be migrated
|
- name: Wait for the instances to be migrated
|
||||||
community.proxmox.proxmox_vm_info:
|
community.proxmox.proxmox_vm_info:
|
||||||
@@ -55,7 +42,7 @@
|
|||||||
register: proxmox_current_instances
|
register: proxmox_current_instances
|
||||||
retries: 20
|
retries: 20
|
||||||
delay: 30
|
delay: 30
|
||||||
until: proxmox_current_instances.proxmox_vms | selectattr('hastate', 'defined') | selectattr('hastate', 'equalto', 'started') | list | length == 0
|
until: proxmox_current_instances.proxmox_vms | selectattr('hastate', 'equalto', 'started') | list | length == 0
|
||||||
|
|
||||||
- name: Run the full-upgrade
|
- name: Run the full-upgrade
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
@@ -94,11 +81,33 @@
|
|||||||
split('/') | first | list
|
split('/') | first | list
|
||||||
check_mode: true
|
check_mode: true
|
||||||
|
|
||||||
- name: Autoremove apt packages
|
- name: Disable maintenance node
|
||||||
ansible.builtin.apt:
|
ansible.builtin.command:
|
||||||
autoremove: true
|
argv:
|
||||||
purge: true
|
- ha-manager
|
||||||
|
- crm-command
|
||||||
|
- node-maintenance
|
||||||
|
- disable
|
||||||
|
- "{{ inventory_hostname_short }}"
|
||||||
become: true
|
become: true
|
||||||
|
register: proxmox_maintenance_disabled
|
||||||
|
changed_when: proxmox_maintenance_disabled.rc == 0
|
||||||
|
|
||||||
- name: Flush handlers
|
- name: Wait for the node to come out of maintenance
|
||||||
ansible.builtin.meta: flush_handlers
|
ansible.builtin.command: # noqa: no-changed-when
|
||||||
|
argv:
|
||||||
|
- ha-manager
|
||||||
|
- status
|
||||||
|
become: true
|
||||||
|
register: proxmox_ha_manager_status
|
||||||
|
changed_when: >-
|
||||||
|
proxmox_ha_manager_status.stdout_lines |
|
||||||
|
select('search', 'lrm ' + inventory_hostname_short) |
|
||||||
|
regex_search('active', ignorecase=true)
|
||||||
|
retries: 20
|
||||||
|
delay: 30
|
||||||
|
until: >-
|
||||||
|
not
|
||||||
|
proxmox_ha_manager_status.stdout_lines |
|
||||||
|
select('search', 'lrm ' + inventory_hostname_short) |
|
||||||
|
regex_search('active', ignorecase=true)
|
||||||
|
|||||||
Reference in New Issue
Block a user