Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired...

35
Deploying Complex Stacks with Ansible Devconf 2020 - 2020-01-24 Will Foster • @sadsfae github.com/sadsfae • https://hobo.house

Transcript of Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired...

Page 1: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Deploying Complex Stacks with AnsibleDevconf 2020 - 2020-01-24

Will Foster • @sadsfae github.com/sadsfae • https://hobo.house

Page 2: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Client-less configuration management system● Written in Python● Uses SSH as a transport mechanism● Uses YAML for logic and tasks● Uses Jinja2 for templating

What is Ansible?

Page 3: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Save time and resources so you can do other things● Significantly lower deployment time for apps / services● Reduce complexity and human error via automation

Why should I use Ansible?

Page 4: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Strive for idempotency. ○ Ansible should do nothing if in desired state

● Template as many configuration files as possible● Break deployment pieces/objectives into logical parts● Make liberal use of configuration variables● Aim for an open-ended design and choice● Use Ansible provided modules wherever possible

Configuration Management Goals

Page 5: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

How Baby Yoda Writes Ansible

Page 6: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Deploy a full all-in-one ELK/EFK 6.8.x stack○ Elasticsearch (search engine, time-series datastore)○ Logstash (data collection, log parsing engine)

○ Kibana (analytics, visualization)

○ Nginx (web reverse proxy)

● We’ll use CentOS7

● Code here: github.com/sadsfae/ansible-elk

Complex Stack Example: ELK/EFK

Page 7: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● host-02 (client) →○ Send system logs via Filebeat to Logstash on host-01

● host-01 (server) → ○ Logstash accepts system logs over SSL/TLS○ Logstash filters logs and sends to Elasticsearch○ We visualize events in Kibana Web UI

DEMO: ELK/EFK Deployed via Ansible

Page 8: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

You’ve had your snack, you’ve played with the buttonNow it’s time to put your jammies on.

Page 9: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives
Page 10: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Ansible Facts can Customize your Environment

Page 11: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Example: automatically tune Elasticsearch JVM heapsize based on amount of physical memory detected

Use System Facts to Adjust Configuration

Page 12: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Handling Service Dependencies in Ansible

Page 13: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● When components depend on other components, check they are available before proceeding

● Can be done by HTTP return code, port, or web content

Make use of Service Dependency Checking

Page 14: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● wait_for, until and uri Ansible modules are useful for this

Make use of Service Dependency Checking

Page 15: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Parent service availability checks during a playbook run

Make use of Service Dependency Checking

Page 16: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Another example: checking raw output matches what we want before proceeding

Dependency Checking Example - Dell Racadm

Page 17: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Using Variables for Conditional Logic

Page 18: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Complex stacks will inevitably grow to require more deploy options● Maximize the usage of conditional vars to provide choice● Expand options for deployment flexibility (see all.yml)

../install/group_vars/all.yml → → → →

vars_files Make your Playbook more Flexible

Page 19: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Organizing your Playbook and role Hierarchy

Page 20: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Common Design Hierarchy for Large Playbooks

Page 21: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Try to use one role per major component

Page 22: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Use branches to support older versions/series of the stack● Use branches to support deployment to different environments● Gitlab.com offers free, private repositories each with 10Gb of space

Keep your Playbooks in an SCM (Git, etc).

Page 23: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Automate Client Operations When Possible

Page 24: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Make it easy to automate client integration● e.g. SSL/TLS certificate retrieval, client applications / libraries

Make sure you’re automating client-side

Page 25: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

CI / CD and Ansible Lint

Page 26: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Use ansible-lint to test your playbooks

ansible-lint install/*.yml -v

ansible-lint install/roles/*/*/*.yml

Page 27: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Use Travis CI to run Lint on Repos

Full guide at https://hobo.house

Page 28: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

Troubleshooting and Debugging Tips

Page 29: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Useful to determine registers, variable output and stdout

Using Debug in a Playbook

Page 30: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Debug can be useful for informational messages

Using Debug in a Playbook

Running ansible-playbook --check tells you what it would do

Page 31: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Upgrade ELK Stack to 7.x+ (currently at 6.8.x)

● Support multi-node deployments

ansible-elk roadmap

Page 32: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

We use ELK Stack for recording QUADS data

Page 33: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● Manages bare-metal systems and network switch automation based on schedules set in the future

● Powers automation within the Red Hat Scale Lab

● https://quads.dev● github.com/redhat-performance/quads

QUADS is an automation framework

Page 34: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives

● github.com/sadsfae

● https://hobo.house

● Twitter: @sadsfae

● Freenode IRC: sadsfae

Thank you for attending!

Questions, Comments, Discussion?

Page 35: Deploying Complex Stacks with Ansible · 1/20/2020  · Ansible should do nothing if in desired state Template as many configuration files as possible Break deployment pieces/objectives