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
|
dest: /tmp/xen-{{ hostname }}.cfg
|
||||||
mode: "0644"
|
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
|
- name: Create Xen VM
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
@@ -58,8 +68,11 @@
|
|||||||
- /tmp/xen-{{ hostname }}.cfg
|
- /tmp/xen-{{ hostname }}.cfg
|
||||||
register: virtualization_xen_create_result
|
register: virtualization_xen_create_result
|
||||||
changed_when: virtualization_xen_create_result.rc == 0
|
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
|
delegate_to: localhost
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
@@ -67,13 +80,11 @@
|
|||||||
- list
|
- list
|
||||||
register: virtualization_xen_list_result
|
register: virtualization_xen_list_result
|
||||||
changed_when: false
|
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
|
- name: Set VM created fact
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
virtualization_vm_created_in_run: true
|
virtualization_vm_created_in_run: true
|
||||||
when:
|
when: virtualization_xen_create_result is changed
|
||||||
- virtualization_xen_list_result is defined
|
|
||||||
- >-
|
|
||||||
virtualization_xen_list_result.stdout | default('')
|
|
||||||
is search('(?m)^' ~ (hostname | ansible.builtin.regex_escape) ~ '\\s+\\d+\\s')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user