# install guest OS using virt module

**URL:** <https://forum.ansible.com/t/install-guest-os-using-virt-module/21998>\
**Category:** Ansible Project\
**Created:** [July 12, 2016, 10:13pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998 "2016-07-12T22:13:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kai1](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kai1](https://forum.ansible.com/u/Kai1)\
**Post date:** [July 12, 2016, 10:13pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998/1 "2016-07-12T22:13:48Z")

</div>

Dear all!

Does a kind soul have a pointer for me to a more detailed documentation  
of the virt module or of handling libvirt VMs in general?

I can define a VM, I should be able to start/stop it. What I didn't  
figure out yet is how to install the initial OS on the VM (from a  
playbook, of course).

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![Mark\_Janssen](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@Mark\_Janssen](https://forum.ansible.com/u/Mark_Janssen)\
**Post date:** [July 13, 2016, 12:21pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998/2 "2016-07-13T12:21:17Z")

</div>

You can run a kickstart or preseed installation, import disk-images or do various other things… For example see (an old version) of my provisioning config:

[https://github.com/sigio/sigio-provisioning](https://github.com/sigio/sigio-provisioning)

These days I use something a bit different, which isn’t in a releasable form at this time.

---

<div class="post-metadata">

**Author:** ![toshywoshy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/toshywoshy/32/7855_2.png) [@toshywoshy](https://forum.ansible.com/u/toshywoshy)\
**Post date:** [July 13, 2016, 12:25pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998/3 "2016-07-13T12:25:40Z")

</div>

> You can run a kickstart or preseed installation, import disk-images or  
> do various other things... For example see (an old version) of my  
> provisioning config:
> 
> [https://github.com/sigio/sigio-provisioning](https://github.com/sigio/sigio-provisioning)

Here is the one I use :  
&nbsp;&nbsp;[https://github.com/toshywoshy/ansible-role-vminstaller](https://github.com/toshywoshy/ansible-role-vminstaller)  
It is a role so you can import it into your structure.

I still need to push some updates and I have added support for Ubuntu, not yet in the repo, but it gives you a clear idea how to set it up.

---

<div class="post-metadata">

**Author:** ![Kai1](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kai1](https://forum.ansible.com/u/Kai1)\
**Post date:** [July 13, 2016, 1:27pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998/4 "2016-07-13T13:27:57Z")

</div>

Mark, Toshaan,

thanks for your answers.  
So it's not possible using only the provided modules, you have to invoke  
shell commands as well.  
You both use a module "qemu-img" which doesn't seem to be provided with  
ansible by default!?

Thanks & cheers, Kai

---

<div class="post-metadata">

**Author:** ![toshywoshy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/toshywoshy/32/7855_2.png) [@toshywoshy](https://forum.ansible.com/u/toshywoshy)\
**Post date:** [July 13, 2016, 2:22pm UTC](https://forum.ansible.com/t/install-guest-os-using-virt-module/21998/5 "2016-07-13T14:22:40Z")

</div>

Kai,

> Mark, Toshaan,
> 
> thanks for your answers.  
> So it's not possible using only the provided modules, you have to invoke  
> shell commands as well.

Well, it should be possible, with the virt module, run a install XML and then run the post install XML, then you would only use the template and the virt module, however since the virt-install module does this much better and I haven't figured a way how to write an acceptable and nice virt-install ansible module, I use a shell script

> You both use a module "qemu-img" which doesn't seem to be provided with  
> ansible by default!?

Yes, this module was not accepted by Michael very long time ago.  
I just created a PR, let's see if we can get it in now.  
In the mean time if you require it, you can find it at :  
[https://raw.githubusercontent.com/toshywoshy/ansible-vm-install/master/playbooks/library/qemu-img](https://raw.githubusercontent.com/toshywoshy/ansible-vm-install/master/playbooks/library/qemu-img) , this is my old vm install playbook

> Thanks & cheers, Kai

Regards,  
Toshaan.
