SlideShare a Scribd company logo
1 of 55
Download to read offline
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

More Related Content

What's hot

What's hot (20)

Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
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
 
SUSE CaaSP: deploy OpenFaaS and Ethereum Blockchain on Kubernetes
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
 
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 ...
Meetup 23 - 01 - The things I wish I would have known before doing OpenStack ...
 
Tố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 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 core
 
OpenStack Icehouse Overview
OpenStack Icehouse OverviewOpenStack Icehouse Overview
OpenStack Icehouse Overview
 
Docker Datacenter Overview and Production Setup Slides
Docker Datacenter Overview and Production Setup SlidesDocker Datacenter Overview and Production Setup Slides
Docker Datacenter Overview and Production Setup Slides
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
 
fabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShiftfabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShift
 
Building Containers: How Many Ways Are Too Many?
Building Containers: How Many Ways Are Too Many?Building Containers: How Many Ways Are Too Many?
Building Containers: How Many Ways Are Too Many?
 
Kubernetes and Istio
Kubernetes and IstioKubernetes and Istio
Kubernetes and Istio
 
Istio canaries and kubernetes
Istio  canaries and kubernetesIstio  canaries and kubernetes
Istio canaries and kubernetes
 
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...
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...
 
Docker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&ADocker Online Meetup: Infrakit update and Q&A
Docker Online Meetup: Infrakit update and Q&A
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
 
Monitoring kubernetes with prometheus-operator
Monitoring kubernetes with prometheus-operatorMonitoring kubernetes with prometheus-operator
Monitoring kubernetes with prometheus-operator
 
Running stateful services in containers - ContainerDays Boston 2016
Running stateful services in containers - ContainerDays Boston 2016Running stateful services in containers - ContainerDays Boston 2016
Running stateful services in containers - ContainerDays Boston 2016
 
OpenStack in Enterprise
OpenStack in EnterpriseOpenStack in Enterprise
OpenStack in Enterprise
 
Load Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & KubernetesLoad Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & Kubernetes
 
Docker for any type of workload and any IT Infrastructure
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 Orchestration at Production Scale
Docker Orchestration at Production Scale Docker Orchestration at Production Scale
Docker Orchestration at Production Scale
 

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

V Mwarev Storage Intregration
V Mwarev Storage IntregrationV Mwarev Storage Intregration
V Mwarev Storage Intregration
mikhail.mikheev
 
De 03 Introduction To V Cloud Api V1
De 03 Introduction To V Cloud Api V1De 03 Introduction To V Cloud Api V1
De 03 Introduction To V Cloud Api V1
ikewu83
 

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

Salt Cloud vmware-orchestration
Salt Cloud vmware-orchestrationSalt Cloud vmware-orchestration
Salt Cloud vmware-orchestration
 
Lessons On Hyper V
Lessons On Hyper VLessons On Hyper V
Lessons On Hyper V
 
Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008Managing VMware with PowerShell - VMworld 2008
Managing VMware with PowerShell - VMworld 2008
 
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...
Assembling an Open Source Toolchain to Manage Public, Private and Hybrid Clou...
 
V Mwarev Storage Intregration
V Mwarev Storage IntregrationV Mwarev Storage Intregration
V Mwarev Storage Intregration
 
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...
Automating Container Deployments on Virtualization with Ansible: OpenShift on...
 
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013
VMware vCHS, Puppet, and Project Zombie - PuppetConf 2013
 
OpenSource ToolChain for the Hybrid Cloud
OpenSource ToolChain for the Hybrid CloudOpenSource ToolChain for the Hybrid Cloud
OpenSource ToolChain for the Hybrid Cloud
 
VMworld 2013: vCloud Powered HPC is Better and Outperforming Physical
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
 
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)
A 60-minute tour of AWS Compute (November 2016)
 
Introduction To Managing VMware With PowerShell
Introduction To Managing VMware With PowerShellIntroduction To Managing VMware With PowerShell
Introduction To Managing VMware With PowerShell
 
How to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWSHow to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWS
 
Node.js kubernetes-cloud all the buzzwords coming together with microsoft azure
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
 
Virtualization and Cloud Computing with Elastic Server On Demand
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
 
De 03 Introduction To V Cloud Api V1
De 03 Introduction To V Cloud Api V1De 03 Introduction To V Cloud Api V1
De 03 Introduction To V Cloud Api V1
 
Ato2019 weave-services-istio
Ato2019 weave-services-istioAto2019 weave-services-istio
Ato2019 weave-services-istio
 
All Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istioAll Things Open 2019 weave-services-istio
All Things Open 2019 weave-services-istio
 
Weave Your Microservices with Istio
Weave Your Microservices with IstioWeave Your Microservices with Istio
Weave Your Microservices with Istio
 
Handout2o
Handout2oHandout2o
Handout2o
 
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...
VMworld 2013: The Story Behind Designing and Building a Distributed Automatio...
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

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