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
2727
2828- ` libvirt_vm_arch ` : CPU architecture, default is ` x86_64 ` .
2929
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+
3036- ` libvirt_vms ` : list of VMs to be created/destroyed. Each one may have the
3137 following attributes:
3238
Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ libvirt_vms:
6161 # Path to console log file.
6262 console_log_path : " {{ libvirt_vm_console_log_path }}"
6363
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 : " "
6469
6570# ## DEPRECATED ###
6671# Use the above settings for each item within `libvirt_vms`, instead of the
Original file line number Diff line number Diff line change 55 virt :
66 name : " {{ vm.name }}"
77 command : list_vms
8+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
89 register : result
910 become : yes
1011
1314 virt :
1415 name : " {{ vm.name }}"
1516 state : destroyed
17+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
1618 become : yes
1719
1820 - name : Ensure the VM is undefined
1921 virt :
2022 name : " {{ vm.name }}"
2123 command : undefine
24+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
2225 become : yes
2326 when : vm.name in result.list_vms
Original file line number Diff line number Diff line change 66 {{ item.pool }}
77 with_items : " {{ volumes }}"
88 register : volume_result
9+ environment : " {{ libvirt_vm_script_env }}"
910 changed_when :
1011 - volume_result is success
1112 - (volume_result.stdout | from_json).changed | default(True)
Original file line number Diff line number Diff line change 11---
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+
211- include_tasks : autodetect.yml
312 # We don't need to know the engine and emulator if we're not creating any new
413 # VMs.
Original file line number Diff line number Diff line change 11---
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-
122- name : Ensure the VM console log directory exists
133 file :
144 path : " {{ console_log_path | dirname }}"
3121 name : " {{ vm.name }}"
3222 command : define
3323 xml : " {{ lookup('template', 'vm.xml.j2') }}"
24+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
3425 become : true
3526
3627- name : Ensure the VM is running and started at boot
3728 virt :
3829 name : " {{ vm.name }}"
3930 autostart : " {{ autostart | bool }}"
4031 state : " {{ 'running' if (start | bool) else 'shutdown' }}"
32+ uri : " {{ libvirt_vm_uri | default(omit, true) }}"
4133 become : true
Original file line number Diff line number Diff line change 11---
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-
112- name : Ensure remote images are downloaded
123 get_url :
134 url : " {{ item }}"
3324 {{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
3425 {% endif %}
3526 with_items : " {{ volumes }}"
36- environment : " {{ libvirt_vm_volume_creation_env }}"
27+ environment : " {{ libvirt_vm_script_env }}"
3728 register : volume_result
3829 changed_when :
3930 - volume_result is success
Original file line number Diff line number Diff line change 44libvirt_vm_log_owner : libvirt-qemu
55
66# 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 44libvirt_vm_log_owner : qemu
55
66# The environment passed to virt_volume.sh
7- libvirt_vm_volume_creation_env :
7+ libvirt_vm_script_env_redhat :
88 VOLUME_GROUP : qemu
99 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