Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided...

30
Deploying Complex Stacks with Ansible Code Europe - 2018-05-08 Will Foster • @sadsfae github.com/sadsfae • https://hobo.house

Transcript of Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided...

Page 1: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Deploying Complex Stacks with AnsibleCode Europe - 2018-05-08

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

Page 2: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Deploy a full all-in-one ELK/EFK 5.6 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 6: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK
Page 7: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Ansible Facts can Customize your Environment

Page 9: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

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

Use System Facts to Adjust Configuration

Page 10: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Handling Service Dependencies in Ansible

Page 11: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 12: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

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

Make use of Service Dependency Checking

Page 13: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Parent service availability checks during a playbook run

Make use of Service Dependency Checking

Page 14: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

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

Dependency Checking Example - Dell Racadm

Page 15: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Using Variables for Conditional Logic

Page 16: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Complex stacks will inevitably grow to require more deploy options● Maximize the usage of conditional vars to provide choice

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

vars_files Make your Playbook more Flexible

Page 17: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Organizing your Playbook and role Hierarchy

Page 18: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Common Design Hierarchy for Large Playbooks

Page 19: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Try to use one role per major component

Page 20: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● 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 21: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Automate Client Operations When Possible

Page 22: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

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

Make sure you’re automating client-side

Page 23: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

Troubleshooting and Debugging Tips

Page 24: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Useful to determine registers, variable output and stdout

Using Debug in a Playbook

Page 25: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Debug can be useful for informational messages

Using Debug in a Playbook

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

Page 26: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● Upgrade ELK Stack to 6.2+ (currently at 5.6)

● Support multi-node deployments

Playbook Updates for ansible-elk

Page 27: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

We use ELK Stack for recording QUADS data

Page 28: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

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

● Powers automation within the Red Hat Scale Lab

● github.com/redhat-performance/quads

QUADS is an automation framework

Page 29: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK

● github.com/sadsfae

● https://hobo.house

● Twitter: @sadsfae

● Freenode IRC: sadsfae

Thank you for attending!

Questions, Comments, Discussion?

Page 30: Deploying Complex Stacks with Ansible - WordPress.com · 2018. 5. 8. · Use Ansible provided modules wherever possible Configuration Management Goals Deploy a full all-in-one ELK/EFK