February 23rd, 2015 by JFrappier

Jonathan Frappier Virtxpert

I wanted to share some of the example Ansible playbooks used during last Wednesday’s US #vBrownBag. During the show I went over examples of how you can use Ansible to create, clone, and update virtual machines in vCenter without the need for other provisioning tools. Based on my testing (and I’m still learning as well), the items noted in the comments are the bare minimum needed to run the playbook, even though the official documentation may currently state otherwise. If you are already using Ansible for configuration management, this is a handy option to have as you can perform the provisioning tasks without leaving Ansible.

All playbooks have been uploaded to my GitHub Ansible-Test-Playbooks repository (https://github.com/jfrappier/ansible-test-playbooks/).

#vBrownBag Using Ansible with vCenter Examples

Posted in Tech Tagged with: , , , , , , , , , , , , , , , , , ,

February 5th, 2015 by JFrappier

Jonathan Frappier Virtxpert

During the #vDM30in30 challenge I started playing with Ansible to get to know it a bit better. One of the things I was curious about is the ability for Ansible to provision virtual machines directly to vCenter. After all if I am using Ansible to manage the configuration of my servers, it would certainly be nice to have a playbook that also deploys my virtual machine, rather than another provisioning tool.

If you don’t already have Ansible up and running, you can get the dependencies installed and Ansible project cloned from GitHub pretty easily with a vanilla CentOS box. Once Ansible is running and you have a playbook or two under your belt you can take a read at the Ansible vsphere_guest docs. This particular module is a bit lacking, I hope to add some updates soon and see if they get accepted.

As they mention in the docs, you will need to have pysphere installed; PySphere being a Python API to support interaction with vSphere/vCenter. PySphere is easy to install if you were able to follow along with my Installing Ansible from Git post; simply run

sudo pip install -U pysphere

With PySphere installed, you are now ready to create your playbook. The playbook example in the Ansible docs seemed to be missing something. Recall from my other posts you typically specify a host (linux box, not vSphere host) in your inventory file and direct the playbook that that host or groups of hosts, for example:

- hosts: db
  remote_user: virtxpert
  sudo: yes
  - name: update mysql-libs-latest 
    yum: pkg=mysql-libs state=latest

But, as you can see in the document ion, you specify the vSphere/ESXi host and vCenter server in the vsphere_guest task. So after a few iterations of trying to get that to work, I came across this page on GitHub. It shows what appears to be essentially dummy text to satisfy the host requirements in the playbook. So my playbook ends up looking like this:

- hosts:
  connection: local
  user: root
  sudo: false
  gather_facts: false
  serial: 1

  - vsphere_guest:
      vcenter_hostname: vxprt-vc01.vxprt.local
      username: [email protected]
      password: ********
      guest: testansible
      state: powered_on
        size_gb: 1
        type: thin
        datastore: vxprt-esxi01-gold-local
        type: vmxnet3
        network: vm
        network_type: standard
        memory_mb: 1024
        num_cpus: 1
        osid: centos64Guest
        scsi: paravirtual
        datacenter: dc01
        hostname: vxprt-esxi01.vxprt.local

With this playbook format in place, I am now able to run the playbook and have the virtual machine created in vCenter.

Playbook success provisioning virtual machine to vCenter

Playbook success provisioning virtual machine to vCenter

vCenter with virtual machine provisioned from Ansible playbook

vCenter with virtual machine provisioned from Ansible playbook

Up next, play around with vars_prompt in place of some of the item names so when the playbook is run, it will prompt the user for input and using Ansible to clone an existing vSphere template.

Deploying Virtual Machines to vCenter with Ansible

Posted in Tech Tagged with: , , , , , , , , , , , , , , , ,