# Create VM with Operating System with Ansible

**URL:** <https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863>\
**Category:** Ansible Project\
**Created:** [July 18, 2022, 2:43pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863 "2022-07-18T14:43:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiuscom1](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@fabiuscom1](https://forum.ansible.com/u/fabiuscom1)\
**Post date:** [July 18, 2022, 2:43pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/1 "2022-07-18T14:43:24Z")

</div>

Hi, i want to do a playbook that create a vm and from iso file, install the operatin system. It’s possible? Thansk

---

<div class="post-metadata">

**Author:** ![Paul\_Manno](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/paul_manno/32/2804_2.png) [@Paul\_Manno](https://forum.ansible.com/u/Paul_Manno)\
**Post date:** [July 18, 2022, 2:44pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/2 "2022-07-18T14:44:53Z")

</div>

Hello,  
I think a tool like hashicorp packer is better suited for this use case.

Best,  
Paul

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 18, 2022, 2:51pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/3 "2022-07-18T14:51:25Z")

</div>

You want to check -

[https://medium.com/@AbhijeetKasurde/automating-centos-7-installation-using-ansible-and-kickstart-483807a3774c](https://medium.com/@AbhijeetKasurde/automating-centos-7-installation-using-ansible-and-kickstart-483807a3774c)  
[https://medium.com/8042/ansible-automating-windows-server-2012-r2-installation-in-vcenter-227577f5917c](https://medium.com/8042/ansible-automating-windows-server-2012-r2-installation-in-vcenter-227577f5917c)

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [July 18, 2022, 2:58pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/4 "2022-07-18T14:58:15Z")

</div>

Also see [https://wiki.debian.org/DebianInstaller/Preseed](https://wiki.debian.org/DebianInstaller/Preseed) and  
[https://www.debian.org/releases/stable/amd64/apb.en.html](https://www.debian.org/releases/stable/amd64/apb.en.html) if you happen to be  
installing Debian or Devuan. It probably works for Ubuntu as well (but I've  
not tried that).

Antony.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [July 18, 2022, 5:09pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/5 "2022-07-18T17:09:28Z")

</div>

We use Hashicorp Packer to create and maintain Windows Server and Linux VM templates. We then use those templates for server provisioning. We also use packer to maintain AWS AMIs. With packer we can ensure we offer the same source OS configurations across AWS and VMware - same OS families and versions and base configurations. For automated server provisioning this is key because it lets your provisioning workflow make assumptions across all provisioning landscapes as to what is the starting point after the template or AMI is launched. We bake into our templates and AMIs a service account that lets our provisioning process get into the new systems and do privileged tasks. Windows and Linux obviously look different, but all Linux families / versions have the same base config, and all Windows versions have the same base config.

Packer has three stages - builder, provisioner, post-processor.

- The builder stage creates the base image from an ISO (for VMware) or from an AMI (for AWS).
- The provisioner stage logs into that base image and gets it up to the expected base configuration using ansible (and some PowerShell for Windows).
- The post-processor takes the “provisioned” (configured) images and converts them to VMware templates or new AWS AMIs.

I highly recommend learning packer and using it. Learning how to do Debian Preseed or Ubuntu Cloud-Init profiles is a real mess but can be done. Red Hat Kickstart profiles are much easier to build. Windows Server requires learning how to do unattended answer files. All of this is required to master the packer build stage.

A great place to see all this as an example is Jeff Geerling’s Packer Boxes project on GitHub.  
[https://github.com/geerlingguy/packer-boxes](https://github.com/geerlingguy/packer-boxes)

This was the basis for our Image Factory project that maintains our base VMware templates and AWS AMIs.

The vmare\_guest module can easily create VMs from templates. Use packer to maintain the templates. Use Ansible to deploy servers sourcing those templates.

---

<div class="post-metadata">

**Author:** ![Jason\_B](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Jason\_B](https://forum.ansible.com/u/Jason_B)\
**Post date:** [July 19, 2022, 10:22pm UTC](https://forum.ansible.com/t/create-vm-with-operating-system-with-ansible/36863/6 "2022-07-19T22:22:02Z")

</div>

This is exactly what I am planning on doing very soon. I have already collection some docs to read, but I didn’t have this one. I believe that using packer will reduce overhead in managing Actual VMware Templates ( and besides has the added advantage of cloud provisioning ).

On Monday, July 18, 2022 at 10:09:28 AM UTC-7
