Skip to content

Commit

Permalink
support python3, smaller fixes, work on Fedora for casl (#311)
Browse files Browse the repository at this point in the history
* Select correct selinux python library depending on python version

* Add check_mode false to force listing VMs even in check mode

* Add a note that defaults variables must be overwritten in the host's inventory

* Make the ISO unmount handler work by replacing with_items with loops.

The error was: 'dict object' has no attribute \"dict_keys(['../rhel-server-7.5-x86_64-dvd.iso'])\"
Possibly due to Python 3 vs. 2 but it should solve the issue for everybody.

* Make virt-install command generation more readable

* Don't mount iso on boot to avoid breaking boot process of host

* Correct task name for httpd service and leave enable as-is

* Make sure that virt-install has one command per line

Addresses comment #311 (comment)
  • Loading branch information
ericzolf authored and oybed committed Jan 18, 2019
1 parent eea20f0 commit ffb968d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions roles/virt-install/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---

# consider that this role isn't run against the created VMs but against the virtualization host,
# i.e. you can only overwrite these variables in the inventory by defining them at the host level.
# Use the libvirt_... variables to overwrite them at the VM level.

default_http_dir: "/var/www/html"
default_http_host: "192.168.122.1"

Expand Down
5 changes: 2 additions & 3 deletions roles/virt-install/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

- name: 'Unmount install ISO'
mount:
path: "{{ mounted_iso[item] }}"
path: "{{ item.value }}"
state: absent
with_items:
- "{{ mounted_iso.keys() }}"
loop: "{{ mounted_iso | dict2items }}"

- name: 'Remove authorized_keys'
file:
Expand Down
1 change: 1 addition & 0 deletions roles/virt-install/tasks/create_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- name: 'Gather the list of existing VMs'
command: virsh list --name
register: existing_vms
check_mode: false

- name: 'Compose Command for new VM provisioning'
include_tasks: 'virt-install.yml'
Expand Down
5 changes: 2 additions & 3 deletions roles/virt-install/tasks/prereq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
with_items:
- virt-install
- httpd
- libselinux-python
- "{{ ((ansible_python_interpreter | default('somepython'))[-1] == '3') | ternary('python3-libselinux','libselinux-python') }}"

- name: 'Enable and start libvirtd'
service:
name: libvirtd
enabled: yes
state: started

- name: 'Enable and start httpd'
- name: 'Start httpd (leave enabled as-is)'
service:
name: httpd
enabled: no
state: started

- name: 'Enable and start firewalld'
Expand Down
20 changes: 19 additions & 1 deletion roles/virt-install/tasks/virt-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
opts: loop
fstype: iso9660
state: mounted
boot: false # avoids that a dangling mount blocks boot process
notify: 'Unmount install ISO'
when:
- mounted_iso[virtinstall_iso] is not defined
Expand All @@ -76,4 +77,21 @@

- name: "Set Fact for VM command"
set_fact:
virt_install_commands: "{{ virt_install_commands | default([]) + [ ('virt-install' + ' --connect ' + virtinstall_connect + ' --virt-type ' + virtinstall_virt_type + ' --name ' + virtinstall_name + ' --metadata \"title=' + virtinstall_title + ',description=' + virtinstall_description + ',name=' + virtinstall_name + '\"' + virt_install_network_string + ' --memory ' + virtinstall_memory + ' --vcpus ' + virtinstall_vcpus + virt_install_disk_string + ' --os-variant ' + virtinstall_os_variant + ' --location http://' + virtinstall_http_host + '/' + mounted_iso[virtinstall_iso] | basename + ' --initrd-inject=/tmp/' + virtinstall_ksfile | basename + ' --extra-args \"inst.repo=http://' + virtinstall_http_host + '/' + mounted_iso[virtinstall_iso] | basename + ' inst.ks=file:/' + virtinstall_ksfile | basename + '\"' + ' --graphics spice ' + ' --video qxl ' + ' --channel spicevmc ' + ' --autostart ') ] }}"
virt_install_commands: >
{{ virt_install_commands | default([]) + [ ('virt-install'
+ ' --connect ' + virtinstall_connect
+ ' --virt-type ' + virtinstall_virt_type
+ ' --name ' + virtinstall_name
+ ' --metadata "title=' + virtinstall_title + ',description=' + virtinstall_description + ',name=' + virtinstall_name + '"'
+ virt_install_network_string
+ virt_install_disk_string
+ ' --os-variant ' + virtinstall_os_variant
+ ' --memory ' + virtinstall_memory
+ ' --vcpus ' + virtinstall_vcpus
+ ' --location http://' + virtinstall_http_host + '/' + mounted_iso[virtinstall_iso] | basename
+ ' --initrd-inject=/tmp/' + virtinstall_ksfile | basename
+ ' --extra-args "inst.repo=http://' + virtinstall_http_host + '/' + mounted_iso[virtinstall_iso] | basename + ' inst.ks=file:/' + virtinstall_ksfile | basename + '"'
+ ' --graphics spice '
+ ' --video qxl '
+ ' --channel spicevmc '
+ ' --autostart ') ] }}

0 comments on commit ffb968d

Please sign in to comment.