VMWare is a common hypervisor choice in large organizations, and it comes with a zoo of additional tools, options and licenses. But once you add a little bit of OpenSource to the mix, things start to get interesting. There are open APIs which integrate well with Tools like Ansible and InSpec. So it is easy to write your own scripts to verify a configuration or harden a ESX host. We will show you, how we automated our deployment, what problems we encountered and how we added some nice features.
3. Ops: the old days (tm)
T-Systems Multimedia Solutions GmbH
4. Ops: the old days (tm)
T-Systems Multimedia Solutions GmbH
5. Ops: the old days (tm)
handcrafted and sometimes arcane con guration
clusters
parameters for Oracle
the "one" server someone installed
virtualization is just lift and shift
T-Systems Multimedia Solutions GmbH
12. Why Ansible?
because we don't like Puppet
Ansible is simple, agent-less
easy to learn
straight-forward in task execution
Not written in Ruby (looking @ you, Puppet)
T-Systems Multimedia Solutions GmbH
18. Automation is fun!
... or so they say ...
due to "unfortunate circumstances" we lost half
our servers
“
“
T-Systems Multimedia Solutions GmbH
19. Automation is fun!
... or so they say ...
... and we did recover easily
due to "unfortunate circumstances" we lost half
our servers
“
“
T-Systems Multimedia Solutions GmbH
20. Automation is fun!
... or so they say ...
... and we did recover easily
due to "unfortunate circumstances" we lost half
our servers
“
“
T-Systems Multimedia Solutions GmbH
21. Managing ESX Hosts
Prebuild modules for all basic tasks:
Network
Storage
Cluster
vCenter
VM tasks
T-Systems Multimedia Solutions GmbH
22. Managing ESX Hosts (example)
I want to con gure all VLANs for my ESX Cluster
All Hosts should have correct VLAN con guration
All Hosts should be con gured from one source
Adding Hosts and VLANs should be easy
(like a distributed vSwitch)
T-Systems Multimedia Solutions GmbH
27. Managing ESX Hosts (example)
I want to con gure all VLANs for my ESX Cluster
All Hosts should have correct VLAN con g
All Hosts should be con gured from one source
Adding Hosts and VLANs should be easy
(like a distributed vSwitch)
T-Systems Multimedia Solutions GmbH
30. Adding Security to the mix
Telekom security guideline requires all servers to
be hardened
also VMware security guideline:
https://www.vmware.com/security/hardening-
guides.html (beware Excel!)
T-Systems Multimedia Solutions GmbH
31. Hardening an ESX host (example)
VMware Requirement:
Guideline ID: ESXi.disable-mob:
The managed object browser (MOB) provides a
way to explore the object model used by the
VMkernel to manage the host; it enables
con gurations to be changed as well. This
interface is meant to be used primarily for
debugging the vSphere SDK. In Sphere 6.0 this
is disabled by default
T-Systems Multimedia Solutions GmbH
37. Not everything out of the box
moving VMs not implemented in Ansible :(
but Ansible is extensible with Python code
so just write your own module
VMware vSphere API Bindings for Python
(https://github.com/vmware/pyvmomi)
VMware API Docs
Python + API =
T-Systems Multimedia Solutions GmbH
38. Not everything out of the box
we started with Ansible code:
- name: Move VM to target host and DS
delegate_to: localhost
vm_move:
vc_host: "{{ vcenter_host }}"
vc_pass: "{{ vcenter_pass }}"
vc_user: "{{ vcenter_user }}"
vm_name: "{{ inventory_hostname }}"
ds_name: "{{ vm_storage }}"
esx_host: "{{ vm_host }}"
T-Systems Multimedia Solutions GmbH
39. Not everything out of the box
then think about implementation
what needs to be done:
Locate the VM we want to move
T-Systems Multimedia Solutions GmbH
40. Not everything out of the box
then think about implementation
what needs to be done:
Locate the VM we want to move
Locate the target ESX host / storage
T-Systems Multimedia Solutions GmbH
41. Not everything out of the box
then think about implementation
what needs to be done:
Locate the VM we want to move
Locate the target ESX host / storage
check what needs to be changed
T-Systems Multimedia Solutions GmbH
42. Not everything out of the box
then think about implementation
what needs to be done:
Locate the VM we want to move
Locate the target ESX host / storage
check what needs to be changed
move the VM
T-Systems Multimedia Solutions GmbH
43. Not everything out of the box
some boilerplate is needed:
def main():
module = AnsibleModule(
argument_spec=dict(
vc_host = dict(required=True, type='str'),
...
esx_host = dict(required=False, type='str'),
),
)
result = dict(
changed=False, original_message='', message=''
)
# do something
module.exit_json(**result)
T-Systems Multimedia Solutions GmbH
44. Not everything out of the box
vm = get_obj(content, [vim.VirtualMachine], vm_name)
vm_datastore = get_obj(content, [vim.Datastore], ds_name)
dest_host = get_obj(content, [vim.HostSystem], esx_host)
vm_relocate_spec = vim.vm.RelocateSpec()
T-Systems Multimedia Solutions GmbH
45. Not everything out of the box
vm = get_obj(content, [vim.VirtualMachine], vm_name)
vm_datastore = get_obj(content, [vim.Datastore], ds_name)
dest_host = get_obj(content, [vim.HostSystem], esx_host)
vm_relocate_spec = vim.vm.RelocateSpec()
if vm.datastore[0] != vm_datastore:
result['changed'] = True
vm_relocate_spec.datastore = vm_datastore
T-Systems Multimedia Solutions GmbH
46. Not everything out of the box
vm = get_obj(content, [vim.VirtualMachine], vm_name)
vm_datastore = get_obj(content, [vim.Datastore], ds_name)
dest_host = get_obj(content, [vim.HostSystem], esx_host)
vm_relocate_spec = vim.vm.RelocateSpec()
if vm.datastore[0] != vm_datastore:
result['changed'] = True
vm_relocate_spec.datastore = vm_datastore
if vm.runtime.host != dest_host:
result['changed'] = True
vm_relocate_spec.host = dest_host
T-Systems Multimedia Solutions GmbH
47. Not everything out of the box
vm = get_obj(content, [vim.VirtualMachine], vm_name)
vm_datastore = get_obj(content, [vim.Datastore], ds_name)
dest_host = get_obj(content, [vim.HostSystem], esx_host)
vm_relocate_spec = vim.vm.RelocateSpec()
if vm.datastore[0] != vm_datastore:
result['changed'] = True
vm_relocate_spec.datastore = vm_datastore
if vm.runtime.host != dest_host:
result['changed'] = True
vm_relocate_spec.host = dest_host
if result['changed']:
task = vm.Relocate(spec=vm_relocate_spec)
wait_for_task(module, task, si)
T-Systems Multimedia Solutions GmbH
48. Not everything out of the box
VMWare has a tool called govc
https://github.com/vmware/govmomi/tree/mast
er/govc
pretty easy to use from the command line
this can also be included in Ansible scripts
but do I really need to write all this python code?
I'm not a programmer!
“
“
T-Systems Multimedia Solutions GmbH
50. Testing with inSpec
written by Chef guys
originally a fork of serverspec
diverged since then and has gotten many new
features
T-Systems Multimedia Solutions GmbH
51. Testing with inSpec - the test
control 'VM.disable-console-drag-n-drop' do
title 'Explicitly disable copy/paste operations'
vsphere.datacenters.each { |dc|
dc.vms.each { |vm|
describe vm_advancedsetting) do
its(['isolation.tools.dnd.disable'])
{ should eq true }
end
}
}
end
T-Systems Multimedia Solutions GmbH
52. Testing with inSpec - results
VM.disable-console-drag-n-drop
isolation.tools.dnd.disable should eq true
Profile Summary: 136 successful controls, 0 failures
Test Summary: 136 successful, 0 failures, 0 skipped
T-Systems Multimedia Solutions GmbH
55. Ansible logo from redbubble.com
VMWare logo from fujitsu
InSpec logo from sdtimes
Fry from ickr user liliana_von_k
success kid from instagram user laneymg
automate from ickr user Amber Case
Ansible works image from tutorialspoint.com
T-Systems Multimedia Solutions GmbH