fix(virtualization): add xen VM existence check and improve changed_when
This commit is contained in:
@@ -49,6 +49,16 @@
|
||||
dest: /tmp/xen-{{ hostname }}.cfg
|
||||
mode: "0644"
|
||||
|
||||
- name: Check if Xen VM already exists
|
||||
delegate_to: localhost
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- xl
|
||||
- list
|
||||
register: virtualization_xen_pre_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Create Xen VM
|
||||
delegate_to: localhost
|
||||
ansible.builtin.command:
|
||||
@@ -58,8 +68,11 @@
|
||||
- /tmp/xen-{{ hostname }}.cfg
|
||||
register: virtualization_xen_create_result
|
||||
changed_when: virtualization_xen_create_result.rc == 0
|
||||
when: >-
|
||||
not (virtualization_xen_pre_check.stdout | default('')
|
||||
is search('(?m)^' ~ (hostname | ansible.builtin.regex_escape) ~ '\\s+\\d+\\s'))
|
||||
|
||||
- name: Ensure VM is running
|
||||
- name: Verify VM is running
|
||||
delegate_to: localhost
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
@@ -67,13 +80,11 @@
|
||||
- list
|
||||
register: virtualization_xen_list_result
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
failed_when: >-
|
||||
not (virtualization_xen_list_result.stdout | default('')
|
||||
is search('(?m)^' ~ (hostname | ansible.builtin.regex_escape) ~ '\\s+\\d+\\s'))
|
||||
|
||||
- name: Set VM created fact
|
||||
ansible.builtin.set_fact:
|
||||
virtualization_vm_created_in_run: true
|
||||
when:
|
||||
- virtualization_xen_list_result is defined
|
||||
- >-
|
||||
virtualization_xen_list_result.stdout | default('')
|
||||
is search('(?m)^' ~ (hostname | ansible.builtin.regex_escape) ~ '\\s+\\d+\\s')
|
||||
when: virtualization_xen_create_result is changed
|
||||
|
||||
Reference in New Issue
Block a user