Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automating virtual machine templates with Hashi...

Stan Dorsett
December 16, 2016

Automating virtual machine templates with Hashicorp Packer

Presentation used for December 20016 DFW VMUG

Stan Dorsett

December 16, 2016
Tweet

Other Decks in Technology

Transcript

  1. Automating virtual machine templates with Hashicorp Packer Stan Dorsett Automation

    Engineer for VMware vCloud Air [email protected] @standorsett https://www.github.com/sdorsett
  2. What will this talk cover? What is packer? How does

    packer change virtual machine creation? What are the components of a packer template? Demo
  3. What is packer? Packer is an open source tool for

    creating identical machine images for multiple platforms from a single source configuration Packer was created by Hashicorp, the creators of Vagrant
  4. How does packer change virtual machine creation? Packer templates and

    provisioner scripts are their own form of documentation. By using version control ( github, bitbucket ) you get change history for your packer templates. Version control systems allow you to review code prior to merging changes into your Packer templates. The running of Packer template builds can be automated by CI systems, like Jenkins.
  5. What makes up a packer template? Packer templates are written

    as JSON text files. Packer templates are broken into the following sections: Builders Provisioners ( optional ) Post-Processors ( optional ) Variables ( optional )
  6. What makes up a packer template? Builders are responsible for

    generating images or virtual machines on various platforms. Builders are the only required section in a packer template. { "builders": [ { "type": "vmware-iso", "iso_url": "http://old-releases.ubuntu.com/releases/precise/ubuntu-12.04.2-server-amd64.iso", "iso_checksum": "af5f788aee1b32c4b2634734309cc9e9", "iso_checksum_type": "md5", "ssh_username": "packer", "shutdown_command": "shutdown -P now" } ] }
  7. What makes up a packer template? Available builders are: Amazon

    EC2, Azure, CloudStack, DigitalOcean, Docker, Google Compute Engine, OpenStack, Parallels, QEMU, VirtualBox & VMware
  8. What makes up a packer template? Provisioners make additional changes

    inside the image after the operating system has been installed by the builder. { "provisioners": [ { "type": "shell", "inline": ["echo foo"] }, { "type": "shell", "script": "install-vmware-tools.sh", "only": ["vmware-iso"] }, { "type": "file", "source": "app.tar.gz", "destination": "/tmp/app.tar.gz" } ] }
  9. What makes up a packer template? Available provisioners are: Remote

    Shell, Local Shell, File Uploads, PowerShell, Windows Shell, Ansible Local, Ansible Remote, Chef Client, Chef Solo, Puppet Masterless, Puppet Server, Salt, Windows Restart
  10. What makes up a packer template? Post-processors take the image

    exported after builders/provisioners have finshed and perform additional tasks to them. { "post-processors": [ { "type": "compress", "keep_input_artifact": true } ] }
  11. What makes up a packer template? Available provisioners are: Amazon

    Import, Artifice, Atlas, Compress, Checksum, Docker Import, Docker Push, Docker Save, Docker Tag, Google Compute Export, Local Shell, Manifest, Vagrant, Vagrant Cloud & vSphere
  12. What makes up a packer template? User variables must first

    be defined in a variables section within your template. { "variables": { "packer_esxi_host": "", "packer_esxi_host": "" "packer_esxi_password": "" }, "builders": [ { "type": "vmware-iso", "remote_host": "{{user `packer_esxi_host`}}", "remote_username": "{{user `packer_esxi_username`}}", "remote_password": "{{user `packer_esxi_password`}}", // ... } ] }
  13. What makes up a packer template? Variables can be passed

    from the command line when building a template using the -var flag. $ packer build \ -var 'packer_esxi_host=192.168.1.51' \ -var 'packer_esxi_username=root' \ -var 'packer_esxi_password=P@ssword123' \ template.json
  14. What makes up a packer template? Variables can also be

    set from an external JSON file using the -var-file flag. A sample JSON file would contain: Assuming this file was named variables.json we could build our template using the following command: { "packer_esxi_host": "192.168.1.51" "packer_esxi_username": "root" "packer_esxi_password": "P@ssword123" } $ packer build -var-file=variables.json template.json