File tree Expand file tree Collapse file tree 9 files changed +32
-22
lines changed Expand file tree Collapse file tree 9 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ Role Variables
27
27
28
28
- ` libvirt_vm_arch ` : CPU architecture, default is ` x86_64 ` .
29
29
30
+ - ` libvirt_vm_uri ` : Override the libvirt connection URI. See the
31
+ [ libvirt docs] ( https://libvirt.org/remote.html ) docs for more details.
32
+
33
+ - ` libvirt_vm_virsh_default_env ` : Variables contained within this dictionary are
34
+ added to the environment used when executing virsh commands.
35
+
30
36
- ` libvirt_vms ` : list of VMs to be created/destroyed. Each one may have the
31
37
following attributes:
32
38
Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ libvirt_vms:
61
61
# Path to console log file.
62
62
console_log_path : " {{ libvirt_vm_console_log_path }}"
63
63
64
+ # Variables to add to the enviroment that is used to execute virsh commands
65
+ libvirt_vm_virsh_default_env : " {{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if libvirt_vm_uri else {} }}"
66
+
67
+ # Override for the libvirt connection uri. Leave unset to use the default.
68
+ libvirt_vm_uri : " "
64
69
65
70
# ## DEPRECATED ###
66
71
# Use the above settings for each item within `libvirt_vms`, instead of the
Original file line number Diff line number Diff line change 5
5
virt :
6
6
name : " {{ vm.name }}"
7
7
command : list_vms
8
+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
8
9
register : result
9
10
become : yes
10
11
13
14
virt :
14
15
name : " {{ vm.name }}"
15
16
state : destroyed
17
+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
16
18
become : yes
17
19
18
20
- name : Ensure the VM is undefined
19
21
virt :
20
22
name : " {{ vm.name }}"
21
23
command : undefine
24
+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
22
25
become : yes
23
26
when : vm.name in result.list_vms
Original file line number Diff line number Diff line change 6
6
{{ item.pool }}
7
7
with_items : " {{ volumes }}"
8
8
register : volume_result
9
+ environment : " {{ libvirt_vm_script_env }}"
9
10
changed_when :
10
11
- volume_result is success
11
12
- (volume_result.stdout | from_json).changed | default(True)
Original file line number Diff line number Diff line change 1
1
---
2
+ - name : Gather os specific variables
3
+ include_vars : " {{ item }}"
4
+ with_first_found :
5
+ - files :
6
+ - " {{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
7
+ - " {{ ansible_distribution }}.yml"
8
+ - " {{ ansible_os_family }}.yml"
9
+ tags : vars
10
+
2
11
- include_tasks : autodetect.yml
3
12
# We don't need to know the engine and emulator if we're not creating any new
4
13
# VMs.
Original file line number Diff line number Diff line change 1
1
---
2
- - name : Gather os specific variables
3
- include_vars : " {{ item }}"
4
- with_first_found :
5
- - files :
6
- - " {{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
7
- - " {{ ansible_distribution }}.yml"
8
- - " {{ ansible_os_family }}.yml"
9
- skip : true
10
- tags : vars
11
-
12
2
- name : Ensure the VM console log directory exists
13
3
file :
14
4
path : " {{ console_log_path | dirname }}"
31
21
name : " {{ vm.name }}"
32
22
command : define
33
23
xml : " {{ lookup('template', 'vm.xml.j2') }}"
24
+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
34
25
become : true
35
26
36
27
- name : Ensure the VM is running and started at boot
37
28
virt :
38
29
name : " {{ vm.name }}"
39
30
autostart : " {{ autostart | bool }}"
40
31
state : " {{ 'running' if (start | bool) else 'shutdown' }}"
32
+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
41
33
become : true
Original file line number Diff line number Diff line change 1
1
---
2
- - name : Gather os specific variables
3
- include_vars : " {{ item }}"
4
- with_first_found :
5
- - files :
6
- - " {{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
7
- - " {{ ansible_distribution }}.yml"
8
- - " {{ ansible_os_family }}.yml"
9
- tags : vars
10
-
11
2
- name : Ensure remote images are downloaded
12
3
get_url :
13
4
url : " {{ item }}"
33
24
{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
34
25
{% endif %}
35
26
with_items : " {{ volumes }}"
36
- environment : " {{ libvirt_vm_volume_creation_env }}"
27
+ environment : " {{ libvirt_vm_script_env }}"
37
28
register : volume_result
38
29
changed_when :
39
30
- volume_result is success
Original file line number Diff line number Diff line change 4
4
libvirt_vm_log_owner : libvirt-qemu
5
5
6
6
# The environment passed to virt_volume.sh
7
- libvirt_vm_volume_creation_env : {}
7
+ libvirt_vm_script_env : " {{ libvirt_vm_virsh_default_env }} "
Original file line number Diff line number Diff line change 4
4
libvirt_vm_log_owner : qemu
5
5
6
6
# The environment passed to virt_volume.sh
7
- libvirt_vm_volume_creation_env :
7
+ libvirt_vm_script_env_redhat :
8
8
VOLUME_GROUP : qemu
9
9
VOLUME_OWNER : qemu
10
+
11
+ libvirt_vm_script_env : >-
12
+ {{ libvirt_vm_script_env_redhat | combine(libvirt_vm_virsh_default_env) }}
You can’t perform that action at this time.
0 commit comments