OSDC 2018 | Spicing up VMWare with Ansible and InSpec by Martin Schurz and Sebastian Gumprich

NETWAYS
NETWAYSNETWAYS
Spicing up VMware with
Ansible and InSpec
T-Systems Multimedia Solutions GmbH
Martin Schurz
Sebastian Gumprich
T-Systems MMS
T-Systems Multimedia Solutions GmbH
Ops: the old days (tm)
T-Systems Multimedia Solutions GmbH
Ops: the old days (tm)
T-Systems Multimedia Solutions GmbH
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
Ops: slowly improving
reliance on enterprise tools
vSphere / vRealize / vCloud
T-Systems Multimedia Solutions GmbH
Ops: slowly improving
reliance on enterprise tools
vSphere / vRealize / vCloud
T-Systems Multimedia Solutions GmbH
VMware
T-Systems Multimedia Solutions GmbH
We have a lot of pets,
but we need more cattle
T-Systems Multimedia Solutions GmbH
Mantra:
manual work is a bug!
T-Systems Multimedia Solutions GmbH
T-Systems Multimedia Solutions GmbH
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
Ansible - quick rundown
T-Systems Multimedia Solutions GmbH
Ansible modules - many of them
T-Systems Multimedia Solutions GmbH
... except Oracle
pet, not cattle.
T-Systems Multimedia Solutions GmbH
Jenkins incoming
already reliable application deployments
now reliable con guration of servers, too
T-Systems Multimedia Solutions GmbH
Automation is fun!
... or so they say ...
T-Systems Multimedia Solutions GmbH
Automation is fun!
... or so they say ...
due to "unfortunate circumstances" we lost half
our servers
“
“
T-Systems Multimedia Solutions GmbH
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
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
Managing ESX Hosts
Prebuild modules for all basic tasks:
Network
Storage
Cluster
vCenter
VM tasks
T-Systems Multimedia Solutions GmbH
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
Managing ESX Hosts (example)
create a host group (e.g. esx-servers )
Add group_vars:
vlans:
customer1-vlan:
tag: 4006
vswitch: vSwitch0
customer2-vlan:
tag: 4007
vswitch: vSwitch0
...
T-Systems Multimedia Solutions GmbH
Managing ESX Hosts (example)
Add a playbook task:
- hosts: esx-servers
tasks:
- name: "Add VLANs"
local_action:
module: vmware_portgroup
hostname: '{{ ansible_hostname }}'
username: root
password: '{{ esxi_pass }}'
switch_name: "{{ item.value.vswitch }}"
portgroup_name: "{{ item.key }}"
vlan_id: "{{ item.value.tag }}"
validate_certs: false
with_dict: "{{ vlans }}"
T-Systems Multimedia Solutions GmbH
Managing ESX Hosts (example)
rst Ansible run
TASK [Add VLANs] *****************************************
ok: [esx_server] => (item={'value': 
{u'vswitch': u'vSwitch0', u'tag': 4006}, 
'key': u'customer1-vlan'})
changed: [esx_server] => (item={'value': 
{u'vswitch': u'vSwitch0', u'tag': 4007}, 
'key': u'customer2-vlan'})
PLAY RECAP ***********************************************
esx_server : ok=1 changed=1 unreachable=0 failed=0
T-Systems Multimedia Solutions GmbH
Managing ESX Hosts (example)
second Ansible run
TASK [Add VLANs] *****************************************
ok: [esx_server] => (item={'value': 
{u'vswitch': u'vSwitch0', u'tag': 4006}, 
'key': u'customer1-vlan'})
ok: [esx_server] => (item={'value': 
{u'vswitch': u'vSwitch0', u'tag': 4007}, 
'key': u'customer2-vlan'})
PLAY RECAP ***********************************************
esx_server : ok=1 changed=0 unreachable=0 failed=0
T-Systems Multimedia Solutions GmbH
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
Creating VMs - Host variables
vm_cpu: 8
vm_ram: 8
vm_storage: srv_live_vmdata1
vm_host: srv-live-vh07
vm_disksize: 80
default_gateway: 172.31.225.1
network_ether_interfaces:
- vm_net: srv-lgen-app
device: eth0
bootproto: static
address: 172.31.225.36
netmask: 255.255.255.128
onboot: "yes"
dns1: "{{ srv_dns1 }}"
dns2: "{{ srv_dns2 }}"
domain: "{{ srv_domain }}"
T-Systems Multimedia Solutions GmbH
Creating VMs - the Ansible task
- name: Create new VM
vmware_guest:
hostname: "{{ vcenter_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
datacenter: "{{ vcenter_dc }}"
name: "{{ item }}"
template: "{{ vm_template }}"
state: poweredon
wait_for_ip_address: yes
hardware:
memory_mb: "{{hostvars[item]['vm_ram']}}"
num_cpus: "{{hostvars[item]['vm_cpu']}}"
disk:
- size_gb: "{{hostvars[item]['vm_disksize']}}"
datastore: "{{hostvars[item]['vm_storage']}}"
T-Systems Multimedia Solutions GmbH
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
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
Hardening an ESX host (example)
Ansible implementation:
# Guideline ID: ESXi.disable-mob
- name: get | disable MOB
shell: "vim-cmd hostsvc/advopt/view 
Config.HostAgent.plugins.solo.enableMob 
| grep value | cut -d ' ' -f 9"
register: mob_status
changed_when: mob_status.rc > 0
- name: set | disable MOB
shell: "vim-cmd hostsvc/advopt/update 
Config.HostAgent.plugins.solo.enableMob 
bool {{ mob }}"
when: mob not in mob_status.stdout
T-Systems Multimedia Solutions GmbH
Hardening VMs - nding them all!
- name: Find all .vmx files on local store
shell: |
find /vmfs/volumes/datastore/ -name *.vmx
register: found_vms
changed_when: False
T-Systems Multimedia Solutions GmbH
Hardening VMs - changing them
- name: Set VM parameters
lineinfile:
path: "{{ item[1] }}"
regexp: "{{ item[0].key }}"
backrefs: yes
line: "{{ item[0].key }} = "{{ item[0].value }}""
with_nested:
- "{{ parameters_add }}"
- "{{ found_vms }}"
parameters_add:
- { key: isolation.tools.copy.disable, value: TRUE }
- { key: isolation.tools.paste.disable, value: TRUE }
T-Systems Multimedia Solutions GmbH
Managing VMs - deleting them
- name: delete VM
vmware_guest:
vcenter_hostname: "{{ vcenter_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: false
guest: "{{ item }}"
force: true
state: absent # deletion!
with_items: "{{ vm_name }}"
T-Systems Multimedia Solutions GmbH
Managing VMs - making snapshots
- name: Create snapshot of {{vm_name}}
vmware_guest_snapshot:
folder: "/vm/"
name: "{{ vm_name }}"
state: present
snapshot_name: "snap_{{ '%Y-%m-%d-%M' | strftime }}"
T-Systems Multimedia Solutions GmbH
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
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
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
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
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
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
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
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
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
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
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
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
Testing
T-Systems Multimedia Solutions GmbH
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
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
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
Bonus - ansible-cmdb
T-Systems Multimedia Solutions GmbH
The End
Now grab some food!
T-Systems Multimedia Solutions GmbH
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
1 of 55

Recommended

Red Hat Forum Benelux 2015 by
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Microsoft
1.2K views58 slides
Docker Meetup 08 03-2016 by
Docker Meetup 08 03-2016Docker Meetup 08 03-2016
Docker Meetup 08 03-2016Docker
5.4K views23 slides
Online Meetup: Why should container system / platform builders care about con... by
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Docker, Inc.
3K views30 slides
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs... by
Orchestration tool roundup   kubernetes vs. docker vs. heat vs. terra form vs...Orchestration tool roundup   kubernetes vs. docker vs. heat vs. terra form vs...
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs...Nati Shalom
85.2K views77 slides
Your journey into the serverless world by
Your journey into the serverless worldYour journey into the serverless world
Your journey into the serverless worldRed Hat Developers
2.7K views24 slides
Kata Container - The Security of VM and The Speed of Container | Yuntong Jin by
Kata Container - The Security of VM and The Speed of Container | Yuntong Jin	Kata Container - The Security of VM and The Speed of Container | Yuntong Jin
Kata Container - The Security of VM and The Speed of Container | Yuntong Jin Vietnam Open Infrastructure User Group
235 views33 slides

More Related Content

What's hot

Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1 by
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Etsuji Nakai
15.7K views23 slides
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes by
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on KubernetesSUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on KubernetesJuan Herrera Utande
744 views20 slides
Meetup 23 - 01 - The things I wish I would have known before doing OpenStack ... by
Meetup 23 - 01 - The things I wish I would have known before doing OpenStack ...Meetup 23 - 01 - The things I wish I would have known before doing OpenStack ...
Meetup 23 - 01 - The things I wish I would have known before doing OpenStack ...Vietnam Open Infrastructure User Group
341 views29 slides
Tối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G core by
Tối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G coreTối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G core
Tối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G coreVietnam Open Infrastructure User Group
730 views27 slides
OpenStack Icehouse Overview by
OpenStack Icehouse OverviewOpenStack Icehouse Overview
OpenStack Icehouse OverviewOpenStack Foundation
8.3K views18 slides
Docker Datacenter Overview and Production Setup Slides by
Docker Datacenter Overview and Production Setup SlidesDocker Datacenter Overview and Production Setup Slides
Docker Datacenter Overview and Production Setup SlidesDocker, Inc.
3.1K views31 slides

What's hot(20)

Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1 by Etsuji Nakai
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Etsuji Nakai15.7K views
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes by Juan Herrera Utande
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on KubernetesSUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes
Docker Datacenter Overview and Production Setup Slides by Docker, Inc.
Docker Datacenter Overview and Production Setup SlidesDocker Datacenter Overview and Production Setup Slides
Docker Datacenter Overview and Production Setup Slides
Docker, Inc.3.1K views
fabric8 ... and Docker, Kubernetes & OpenShift by roland.huss
fabric8 ... and Docker, Kubernetes & OpenShiftfabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShift
roland.huss9.6K views
Kubernetes and Istio by Ketan Gote
Kubernetes and IstioKubernetes and Istio
Kubernetes and Istio
Ketan Gote154 views
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker... by Uri Cohen
Orchestration tool roundup  - OpenStack Israel summit - kubernetes vs. docker...Orchestration tool roundup  - OpenStack Israel summit - kubernetes vs. docker...
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...
Uri Cohen1.6K views
Docker Online Meetup: Infrakit update and Q&A by Docker, Inc.
Docker Online Meetup: Infrakit update and Q&ADocker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&A
Docker, Inc.6.7K views
Monitoring kubernetes with prometheus-operator by Lili Cosic
Monitoring kubernetes with prometheus-operatorMonitoring kubernetes with prometheus-operator
Monitoring kubernetes with prometheus-operator
Lili Cosic295 views
Running stateful services in containers - ContainerDays Boston 2016 by Jonas Rosland
Running stateful services in containers - ContainerDays Boston 2016Running stateful services in containers - ContainerDays Boston 2016
Running stateful services in containers - ContainerDays Boston 2016
Jonas Rosland6.1K views
OpenStack in Enterprise by Nalee Jang
OpenStack in EnterpriseOpenStack in Enterprise
OpenStack in Enterprise
Nalee Jang901 views
Load Balancing in the Cloud using Nginx & Kubernetes by Lee Calcote
Load Balancing in the Cloud using Nginx & KubernetesLoad Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & Kubernetes
Lee Calcote2.7K views
Docker for any type of workload and any IT Infrastructure by Docker, Inc.
Docker for any type of workload and any IT InfrastructureDocker for any type of workload and any IT Infrastructure
Docker for any type of workload and any IT Infrastructure
Docker, Inc.915 views
Docker Orchestration at Production Scale by Docker, Inc.
Docker Orchestration at Production Scale Docker Orchestration at Production Scale
Docker Orchestration at Production Scale
Docker, Inc.5.2K views

Similar to OSDC 2018 | Spicing up VMWare with Ansible and InSpec by Martin Schurz and Sebastian Gumprich

Salt Cloud vmware-orchestration by
Salt Cloud vmware-orchestrationSalt Cloud vmware-orchestration
Salt Cloud vmware-orchestrationMo Rawi
3.4K views17 slides
Lessons On Hyper V by
Lessons On Hyper VLessons On Hyper V
Lessons On Hyper VAidan Finn
781 views30 slides
Managing VMware with PowerShell - VMworld 2008 by
Managing VMware with PowerShell - VMworld 2008Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008Carter Shanklin
1.4K views24 slides
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou... by
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...POSSCON
709 views45 slides
V Mwarev Storage Intregration by
V Mwarev Storage IntregrationV Mwarev Storage Intregration
V Mwarev Storage Intregrationmikhail.mikheev
586 views38 slides
Automating Container Deployments on Virtualization with Ansible: OpenShift on... by
Automating Container Deployments on Virtualization with Ansible: OpenShift on...Automating Container Deployments on Virtualization with Ansible: OpenShift on...
Automating Container Deployments on Virtualization with Ansible: OpenShift on...Laurent Domb
491 views40 slides

Similar to OSDC 2018 | Spicing up VMWare with Ansible and InSpec by Martin Schurz and Sebastian Gumprich(20)

Salt Cloud vmware-orchestration by Mo Rawi
Salt Cloud vmware-orchestrationSalt Cloud vmware-orchestration
Salt Cloud vmware-orchestration
Mo Rawi3.4K views
Lessons On Hyper V by Aidan Finn
Lessons On Hyper VLessons On Hyper V
Lessons On Hyper V
Aidan Finn781 views
Managing VMware with PowerShell - VMworld 2008 by Carter Shanklin
Managing VMware with PowerShell - VMworld 2008Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008
Carter Shanklin1.4K views
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou... by POSSCON
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...
POSSCON709 views
Automating Container Deployments on Virtualization with Ansible: OpenShift on... by Laurent Domb
Automating Container Deployments on Virtualization with Ansible: OpenShift on...Automating Container Deployments on Virtualization with Ansible: OpenShift on...
Automating Container Deployments on Virtualization with Ansible: OpenShift on...
Laurent Domb491 views
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013 by Puppet
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013
Puppet4.6K views
VMworld 2013: vCloud Powered HPC is Better and Outperforming Physical by VMworld
VMworld 2013: vCloud Powered HPC is Better and Outperforming PhysicalVMworld 2013: vCloud Powered HPC is Better and Outperforming Physical
VMworld 2013: vCloud Powered HPC is Better and Outperforming Physical
VMworld539 views
A 60-minute tour of AWS Compute (November 2016) by Julien SIMON
A 60-minute tour of AWS Compute (November 2016)A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)
Julien SIMON485 views
Introduction To Managing VMware With PowerShell by Hal Rottenberg
Introduction To Managing VMware With PowerShellIntroduction To Managing VMware With PowerShell
Introduction To Managing VMware With PowerShell
Hal Rottenberg971 views
How to build a Citrix infrastructure on AWS by Denis Gundarev
How to build a Citrix infrastructure on AWSHow to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWS
Denis Gundarev11.1K views
Node.js kubernetes-cloud all the buzzwords coming together with microsoft azure by Patriek van Dorp
Node.js kubernetes-cloud all the buzzwords coming together with microsoft azureNode.js kubernetes-cloud all the buzzwords coming together with microsoft azure
Node.js kubernetes-cloud all the buzzwords coming together with microsoft azure
Patriek van Dorp372 views
Virtualization and Cloud Computing with Elastic Server On Demand by Yan Pritzker
Virtualization and Cloud Computing with Elastic Server On DemandVirtualization and Cloud Computing with Elastic Server On Demand
Virtualization and Cloud Computing with Elastic Server On Demand
Yan Pritzker33.5K views
De 03 Introduction To V Cloud Api V1 by ikewu83
De 03 Introduction To V Cloud Api V1De 03 Introduction To V Cloud Api V1
De 03 Introduction To V Cloud Api V1
ikewu831.2K views
Weave Your Microservices with Istio by All Things Open
Weave Your Microservices with IstioWeave Your Microservices with Istio
Weave Your Microservices with Istio
All Things Open344 views
All Things Open 2019 weave-services-istio by Lin Sun
All Things Open 2019 weave-services-istioAll Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istio
Lin Sun97 views
Ato2019 weave-services-istio by Lin Sun
Ato2019 weave-services-istioAto2019 weave-services-istio
Ato2019 weave-services-istio
Lin Sun98 views
VMworld 2013: The Story Behind Designing and Building a Distributed Automatio... by VMworld
VMworld 2013: The Story Behind Designing and Building a Distributed Automatio...VMworld 2013: The Story Behind Designing and Building a Distributed Automatio...
VMworld 2013: The Story Behind Designing and Building a Distributed Automatio...
VMworld208 views

Recently uploaded

AI and Ml presentation .pptx by
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptxFayazAli87
13 views15 slides
Airline Booking Software by
Airline Booking SoftwareAirline Booking Software
Airline Booking SoftwareSharmiMehta
7 views26 slides
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...NimaTorabi2
15 views17 slides
Top-5-production-devconMunich-2023.pptx by
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptxTier1 app
8 views40 slides
predicting-m3-devopsconMunich-2023.pptx by
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptxTier1 app
7 views24 slides
SAP FOR TYRE INDUSTRY.pdf by
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdfVirendra Rai, PMP
28 views3 slides

Recently uploaded(20)

AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8713 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta7 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi215 views
Top-5-production-devconMunich-2023.pptx by Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app8 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app7 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic14 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino6 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation by HCLSoftware
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook AutomationDRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
DRYiCE™ iAutomate: AI-enhanced Intelligent Runbook Automation
HCLSoftware6 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller42 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite5 views
Sprint 226 by ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ10 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492143 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok15 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views

OSDC 2018 | Spicing up VMWare with Ansible and InSpec by Martin Schurz and Sebastian Gumprich

  • 1. Spicing up VMware with Ansible and InSpec T-Systems Multimedia Solutions GmbH
  • 2. Martin Schurz Sebastian Gumprich T-Systems MMS T-Systems Multimedia Solutions GmbH
  • 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
  • 6. Ops: slowly improving reliance on enterprise tools vSphere / vRealize / vCloud T-Systems Multimedia Solutions GmbH
  • 7. Ops: slowly improving reliance on enterprise tools vSphere / vRealize / vCloud T-Systems Multimedia Solutions GmbH
  • 9. We have a lot of pets, but we need more cattle T-Systems Multimedia Solutions GmbH
  • 10. Mantra: manual work is a bug! 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
  • 13. Ansible - quick rundown T-Systems Multimedia Solutions GmbH
  • 14. Ansible modules - many of them T-Systems Multimedia Solutions GmbH
  • 15. ... except Oracle pet, not cattle. T-Systems Multimedia Solutions GmbH
  • 16. Jenkins incoming already reliable application deployments now reliable con guration of servers, too T-Systems Multimedia Solutions GmbH
  • 17. Automation is fun! ... or so they say ... 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
  • 23. Managing ESX Hosts (example) create a host group (e.g. esx-servers ) Add group_vars: vlans: customer1-vlan: tag: 4006 vswitch: vSwitch0 customer2-vlan: tag: 4007 vswitch: vSwitch0 ... T-Systems Multimedia Solutions GmbH
  • 24. Managing ESX Hosts (example) Add a playbook task: - hosts: esx-servers tasks: - name: "Add VLANs" local_action: module: vmware_portgroup hostname: '{{ ansible_hostname }}' username: root password: '{{ esxi_pass }}' switch_name: "{{ item.value.vswitch }}" portgroup_name: "{{ item.key }}" vlan_id: "{{ item.value.tag }}" validate_certs: false with_dict: "{{ vlans }}" T-Systems Multimedia Solutions GmbH
  • 25. Managing ESX Hosts (example) rst Ansible run TASK [Add VLANs] ***************************************** ok: [esx_server] => (item={'value': {u'vswitch': u'vSwitch0', u'tag': 4006}, 'key': u'customer1-vlan'}) changed: [esx_server] => (item={'value': {u'vswitch': u'vSwitch0', u'tag': 4007}, 'key': u'customer2-vlan'}) PLAY RECAP *********************************************** esx_server : ok=1 changed=1 unreachable=0 failed=0 T-Systems Multimedia Solutions GmbH
  • 26. Managing ESX Hosts (example) second Ansible run TASK [Add VLANs] ***************************************** ok: [esx_server] => (item={'value': {u'vswitch': u'vSwitch0', u'tag': 4006}, 'key': u'customer1-vlan'}) ok: [esx_server] => (item={'value': {u'vswitch': u'vSwitch0', u'tag': 4007}, 'key': u'customer2-vlan'}) PLAY RECAP *********************************************** esx_server : ok=1 changed=0 unreachable=0 failed=0 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
  • 28. Creating VMs - Host variables vm_cpu: 8 vm_ram: 8 vm_storage: srv_live_vmdata1 vm_host: srv-live-vh07 vm_disksize: 80 default_gateway: 172.31.225.1 network_ether_interfaces: - vm_net: srv-lgen-app device: eth0 bootproto: static address: 172.31.225.36 netmask: 255.255.255.128 onboot: "yes" dns1: "{{ srv_dns1 }}" dns2: "{{ srv_dns2 }}" domain: "{{ srv_domain }}" T-Systems Multimedia Solutions GmbH
  • 29. Creating VMs - the Ansible task - name: Create new VM vmware_guest: hostname: "{{ vcenter_host }}" username: "{{ vcenter_user }}" password: "{{ vcenter_pass }}" datacenter: "{{ vcenter_dc }}" name: "{{ item }}" template: "{{ vm_template }}" state: poweredon wait_for_ip_address: yes hardware: memory_mb: "{{hostvars[item]['vm_ram']}}" num_cpus: "{{hostvars[item]['vm_cpu']}}" disk: - size_gb: "{{hostvars[item]['vm_disksize']}}" datastore: "{{hostvars[item]['vm_storage']}}" 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
  • 32. Hardening an ESX host (example) Ansible implementation: # Guideline ID: ESXi.disable-mob - name: get | disable MOB shell: "vim-cmd hostsvc/advopt/view Config.HostAgent.plugins.solo.enableMob | grep value | cut -d ' ' -f 9" register: mob_status changed_when: mob_status.rc > 0 - name: set | disable MOB shell: "vim-cmd hostsvc/advopt/update Config.HostAgent.plugins.solo.enableMob bool {{ mob }}" when: mob not in mob_status.stdout T-Systems Multimedia Solutions GmbH
  • 33. Hardening VMs - nding them all! - name: Find all .vmx files on local store shell: | find /vmfs/volumes/datastore/ -name *.vmx register: found_vms changed_when: False T-Systems Multimedia Solutions GmbH
  • 34. Hardening VMs - changing them - name: Set VM parameters lineinfile: path: "{{ item[1] }}" regexp: "{{ item[0].key }}" backrefs: yes line: "{{ item[0].key }} = "{{ item[0].value }}"" with_nested: - "{{ parameters_add }}" - "{{ found_vms }}" parameters_add: - { key: isolation.tools.copy.disable, value: TRUE } - { key: isolation.tools.paste.disable, value: TRUE } T-Systems Multimedia Solutions GmbH
  • 35. Managing VMs - deleting them - name: delete VM vmware_guest: vcenter_hostname: "{{ vcenter_host }}" username: "{{ vcenter_user }}" password: "{{ vcenter_pass }}" validate_certs: false guest: "{{ item }}" force: true state: absent # deletion! with_items: "{{ vm_name }}" T-Systems Multimedia Solutions GmbH
  • 36. Managing VMs - making snapshots - name: Create snapshot of {{vm_name}} vmware_guest_snapshot: folder: "/vm/" name: "{{ vm_name }}" state: present snapshot_name: "snap_{{ '%Y-%m-%d-%M' | strftime }}" 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
  • 53. Bonus - ansible-cmdb T-Systems Multimedia Solutions GmbH
  • 54. The End Now grab some food! 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