entire lifecycle of server development and deployment: • Flawless production deployments • Repeatable environment builds • Infrastructure testing & validation • Seamless flow between developers and ops
Ansible? • How to write an Ansible playbook Part 2: Ansible in the DevOps Lifecycle • Local Development w/ Vagrant & Serverspec • Continuous Integration w/ Circle CI & AWS • Environment build-out & testing w/ AWS AMI & ASG
SparkBase • Fantasy sports websites ◦ Manage 25 servers ◦ 100,000 uniques per day ◦ 700 requests per second • Been using Ansible for last 8 months • Developing a fully tested DevOps process • Building production servers this month with this approach
DevOps differently ◦ Ansible doesn’t have good built-in testing1 ◦ CI is largely ignored ◦ Differences in building vs. provisioning servers • Present and receive feedback on my approach • Curious how others are using Ansible 1 http://docs.ansible.com/test_strategies.html “Ansible resources are models of desired-state. As such, it should not be necessary to test that services are running, packages are installed, or other such things.”
Uses YAML syntax to define the state a server should have • Converts YAML statements into bash commands that are run on remote server via SSH • Adhoc and playbooks
multi-machine deployment system • Contains one or more plays • Requires a host to be specified --- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted webservers.yml
can execute multiple roles against a server • Ansible Galaxy is the public repository of shared roles --- - hosts: webservers roles: - common - webservers webservers.yml
• Host Vars • Group Vars Vault: • Password-protect secrets while keeping them in source control ansible-playbook test.yml --extra-vars=”foo=bar” - hosts: webservers vars: http_port: 80 group_vars/webservers/main.yml --- - http_port: 80
and their addresses in a file • Must be manually updated Dynamic Inventory • Uses APIs from hosting provider (AWS) to generate a list of servers • Add meta data to each server, such as tags, that can be referenced in playbooks • Highly recommended when using a cloud provider
Defined by an AMI • Rules for scaling up and down (optional) • Allows for multi-AZ redundancy • Netflix model • Useful even for a single server ◦ max instances = 1 ◦ min instances = 1
◦ Vagrant ◦ Serverspec ◦ Circle CI ◦ AWS • Do as much in Ansible as possible https://github.com/kday/ansible-from-playbook-to-production [email protected] @kday