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

Build Immutable Servers with Packer & Ansible @ PixelsCamp 2017

Daniel Gomes
September 29, 2017

Build Immutable Servers with Packer & Ansible @ PixelsCamp 2017

Slides of my talk about "Build Immutable Servers with Packer & Ansible" at Pixels Camp in Lisbon, Portugal.

The code samples can be found here: https://github.com/dcsg/build-immutable-servers-packer-ansible

Daniel Gomes

September 29, 2017

More Decks by Daniel Gomes

Other Decks in Technology


  1. About me • Team Lead at Talkdesk • @phplx co-founder

    • @_dcsg • dcsg.me Daniel Gomes
  2. Configuration Drift • Manual ad-hoc changes and updates to servers

    that are not recorded • Servers in your infrastructure became more and more different from each others @_dcsg #PixelsCamp
  3. The cluster state after a few weeks State A @_dcsg

    #PixelsCamp State C State B State B
  4. Snowflake Server • Long running servers • Difficult to reproduce

    • No consistency between servers • Lack of confidence in your systems • Hard to spin up another instance in the same state @_dcsg https://martinfowler.com/bliki/SnowflakeServer.html
  5. Configuration Management The process of systematically handling changes to a

    system in a way that it maintains integrity over time. @_dcsg #PixelsCamp
  6. Configuration Management Spin up Base Image Run Config Management Server

    in desired state Changes Edit config file Upgrade/install package … Running Server
  7. Applying to the cluster state State A @_dcsg #PixelsCamp State

    C State B State B Config Management Apply State D
  8. How does Ansible work? • Agent-less by operating over SSH

    • Ad-hoc commands execution • Playbooks @_dcsg #PixelsCamp
  9. Ansible terminology • Inventory of hosts - your raw materials

    (servers) • Modules - your tools (apt, yum, etc) • Playbooks - your instructions manual (executes tasks) @_dcsg #PixelsCamp
  10. Quick recap • Configuration Drift • Problems of the Snowflake

    Servers • Configuration Management • Ansible @_dcsg #PixelsCamp
  11. “A server should be like a phoenix, regularly rising from

    the ashes.” - Martin Fowler in PhoenixServer @_dcsg #PixelsCamp
  12. Phoenix Servers • Avoid configuration drifts • Disposable servers •

    Servers can be built from scratch @_dcsg #PixelsCamp
  13. The cluster Re-launch an instance State D @_dcsg #PixelsCamp State

    D State D State D Terminate 
 Instance Config Management Apply State D State D
  14. Built Process Spin up Base Image Run Config Management Server

    in desire state Install packages Create folders Create user Upload app etc Run Config Management Repositories unavailable
  15. "An Immutable Server is a server, that once deployed, is

    never modified, merely replaced with a new updated instance." - Kief Morris in ImmutableServer @_dcsg #PixelsCamp
  16. Immutable Servers • Final state image with everything baked in.

    • No changes after it’s built. • Include scripts to start the application at boot. • Easy to scale out, deploy and rollback. • Trustable and testable. • Easy to adopt A/B testing, Canary releases or Blue/Green deployments. @_dcsg #PixelsCamp
  17. Immutable Server Build Process Bake In the App App Final

    Image Server in desire state configure application
 environment Spin up Base Image Run Config Management (puppet, chef, ansible)
  18. Build Image Stages Flow Example Base Image OS Hardening Common

 (vim, htop, etc) etc Application Base Image Install necessary software to run the App Create user/folders Application Final Image Upload App Script to run App at boot System upgrades & Security updates Application security, package, configuration updates
  19. • SnowFlake Servers • Inconsistent states between machine (Config Drifts)

    • Phoenix Servers • Avoids Config Drifts using CM Automation Tools • Can be built from scratch • Immutable Servers • Final image with everything baked in • After built cannot be modified • Can only be replaced with an updated instance Recap
  20. What’s Packer? • Tool for creating identical machine images •

    For multiple platforms and in Parallel @_dcsg https://www.packer.io/
  21. Packer terminology • Artifact • Builders • Builds • Commands

    • Post-processors • Provisioners • Templates @_dcsg https://www.packer.io/