Files
role_proxmox/handlers/main.yml

94 lines
3.1 KiB
YAML

---
# handlers file for proxmox
- name: Configure cloud-init
community.proxmox.proxmox_kvm:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
agent: "enabled=1,fstrim_cloned_disks=1"
cipassword: "{{ proxmox_instance_cloudinit_cipassword }}"
ciuser: "{{ proxmox_instance_cloudinit_ciuser }}"
ciupgrade: false
ide:
ide2: "{{ proxmox_instance_disks[0].storage }}:cloudinit"
ipconfig: "{{ proxmox_instance_ipconfig }}"
name: "{{ inventory_hostname }}"
nameservers: "{{ proxmox_instance_cloudinit_nameservers }}"
node: "{{ proxmox_instance_node }}"
searchdomains: "{{ proxmox_instance_cloudinit_searchdomains }}"
sshkeys: "{{ proxmox_instance_cloudinit_sshkeys }}"
vmid: "{{ proxmox_instance_vmid }}"
update: true
update_unsafe: true
when: proxmox_instance_cloudinit
delegate_to: "{{ proxmox_delegate_to | default(omit) }}"
- name: Start instance
community.proxmox.proxmox_kvm:
api_host: "{{ proxmox_api_host }}"
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
name: "{{ inventory_hostname }}"
node: "{{ proxmox_instance_node }}"
state: started
when:
- proxmox_start_instance
- not rebooted.changed
delegate_to: "{{ proxmox_delegate_to | default(omit) }}"
- name: Wait SSH port is open
ansible.builtin.wait_for:
host: "{{ proxmox_instance_ssh_ip }}"
port: "{{ proxmox_instance_ssh_port }}"
search_regex: OpenSSH
delay: 30
when: proxmox_start_instance
delegate_to: "{{ proxmox_delegate_to | default(omit) }}"
- name: Wait cloud-init
ansible.builtin.command:
cmd: cloud-init status
when: proxmox_instance_cloudinit
register: cloudinit_status
changed_when: cloudinit_status.stdout_lines | select("search", "done") | list | length > 0
failed_when: cloudinit_status.rc == 1
until: cloudinit_status.stdout_lines | select("search", "done") | list | length > 0
retries: 100
delay: 36
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