aws meetup - sydney - march

45
A journey with Ansible & AWS Steven Ringo

Upload: markghiasy

Post on 18-Jul-2015

128 views

Category:

Business


0 download

TRANSCRIPT

Page 1: AWS Meetup - Sydney - March

A journey with Ansible & AWSSteven Ringo

Page 2: AWS Meetup - Sydney - March

CochlearSharing of patient-related data

among clinics and servicecentres.

Page 3: AWS Meetup - Sydney - March

Challenges

Page 4: AWS Meetup - Sydney - March

Regulatory & Compliance

Security

Sovereignty

Privacy

Geographic

Page 5: AWS Meetup - Sydney - March

Cultural

Organisational

Legal

Page 6: AWS Meetup - Sydney - March

Manage

Scale

Secure

Maintain

Page 7: AWS Meetup - Sydney - March

Infrastructure as codeSource control

Audit trail

Self documenting

Shared knowledge base

Page 8: AWS Meetup - Sydney - March

Desired resultsAgility

Convenience

Automation

Sandboxes, throwaway & testenvironments

Page 9: AWS Meetup - Sydney - March

bash

Page 10: AWS Meetup - Sydney - March

Let's create anew user

Page 11: AWS Meetup - Sydney - March

StackOverflow to the rescue!

sudo useradd myusersudo useradd -m myusersudo passwd myusersudo usermod -s /bin/bash myuser

Page 12: AWS Meetup - Sydney - March

Oh f*#&. User exists!

How to change home folder?

sudo?

useradd or adduser?

Ubuntu vs RedHat.

Page 13: AWS Meetup - Sydney - March

# Add the user 'borat' with a bash shell, # appending the group 'admins'# and 'developers' to the user's groups

- user: name: borat shell: /bin/bash groups: kazakhs append: yes

Page 14: AWS Meetup - Sydney - March

Idempotence

Page 15: AWS Meetup - Sydney - March

The ability to run an operationthat produces the same resultregardless of how many times

it is run.

Page 16: AWS Meetup - Sydney - March

SSH

Page 17: AWS Meetup - Sydney - March

No agents

Page 18: AWS Meetup - Sydney - March

Open source

Page 19: AWS Meetup - Sydney - March

Reads like prose

Declarative

YAML

Page 20: AWS Meetup - Sydney - March

Instant start.

Install locally and go!Small learning curve to get started

Page 21: AWS Meetup - Sydney - March

RHEL, CentOS, Fedora

Debian, Ubuntu

OS X

Windows*

Page 22: AWS Meetup - Sydney - March

“I wrote Ansible because noneof the existing tools fit mybrain. I wanted a tool that Icould not use for 6 months,come back later, and still

remember how it worked”— Michael De Haan. Ansible project founder

Page 23: AWS Meetup - Sydney - March

Cloud - Commands - Database - Files - Inventory

Messaging - Monitoring - Network - Notification

Packaging - Source - Control - System - Utilities

Web Infrastructure - Windows

Page 24: AWS Meetup - Sydney - March

AWS Modulesec2 Create, terminate, start or stop an instance in ec2ec2_ami Create or destroy an image in ec2ec2_ami_search Retrieve AWS AMI information for a given operating system.ec2_asg Create or delete AWS Autoscaling Groupsec2_eip Associate an EC2 elastic IP with an instance.ec2_elb Deregisters or registers instances from EC2 ELBsec2_elb_lb Creates or destroys Amazon ELB.ec2_facts Gathers facts about remote hosts within ec2 (aws)ec2_group Maintain an ec2 VPC security group.ec2_key Maintain an ec2 key pair.ec2_lc Create or delete AWS Autoscaling Launch Configurationsec2_metric_alarm Create/update or delete AWS Cloudwatch ‘metric alarms’ec2_scaling_policy Create or delete AWS scaling policies for Autoscaling groupsec2_snapshot Creates a snapshot from an existing volumeec2_tag Create and remove tag(s) to ec2 resources.ec2_vol Create and attach a volume, return volume id and device mapec2_vpc Configure AWS virtual private clouds

Page 25: AWS Meetup - Sydney - March

AWS Modulescloudformation Create a AWS CloudFormation stackelasticache Manage cache clusters in Amazon Elasticache.rds Create, delete, or modify an Amazon rds instancerds_param_group Manage RDS parameter groupsrds_subnet_group Manage RDS database subnet groupsroute53 Add or delete entries in Amazons Route53 DNS services3 S3 module putting a file into S3.

Page 26: AWS Meetup - Sydney - March

AnsibleConcepts

Page 27: AWS Meetup - Sydney - March

ModuleAbstraction of a thing that does stuff

Page 28: AWS Meetup - Sydney - March

TaskUse a module with desired parameters

Page 29: AWS Meetup - Sydney - March

# Remove the user 'johnd'- user: name=johnd state=absent remove=yes

Page 30: AWS Meetup - Sydney - March

PlayA list of tasks

for a list of hosts

Page 31: AWS Meetup - Sydney - March

---

- name: install The Thing™

hosts: webserver

remote_user: deploy

sudo: yes

tasks:

- name: create log file in /var/log

file: path="/var/log/csds" state=directory owner={{ deploy_user }} group={{ deploy_user }} mode=0755

- name: write nginx config file

template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf mode=0755

notify: restart nginx

- name: check if database exists using result of create database task

postgresql_db: name={{ postgresql_db }} encoding='UTF-8'

register: create_database_result

- name: create postgresql user

postgresql_user: name={{ postgresql_user }} db={{ postgresql_db }} role_attr_flags=CREATEDB,NOSUPERUSER

Page 32: AWS Meetup - Sydney - March

PlaybookCollections of plays

Page 33: AWS Meetup - Sydney - March

PlaybookDeploy a Rails app

With Postgres

From the demo/demo GitHub repo

To an AWS instance in Sydney

On Ubuntu 14.04

As the Deploy user

Page 34: AWS Meetup - Sydney - March

TemplatesFiles copied to hosts

Written in Jinja

Similar to erb, handlebars etc.

Page 35: AWS Meetup - Sydney - March

Templatevariable substitution from calling playbookconditionals and loopstext transform filters

Page 36: AWS Meetup - Sydney - March

InventoryList of managed hosts and metadata for

where you want to deploy.

Static list

Dynamically generated list (e.g. EC2)

Page 37: AWS Meetup - Sydney - March

mail.example.com

[webservers]foo.example.com http_port=8080 data_dir=/var/www/data/foobar.example.com

[dbservers]one.example.comtwo.example.comthree.example.com

Page 38: AWS Meetup - Sydney - March

HandlersTake an action upon a change of state

e.g. restart a service

Page 39: AWS Meetup - Sydney - March

PluginsCallback, action and other hooks

Page 40: AWS Meetup - Sydney - March

“Chatops”Send a Slack message

at playbook start or end

Page 41: AWS Meetup - Sydney - March

FactsData gathered

from target hostsIP addressHardwareOperating SystemEnvironment variables, etc.

Page 42: AWS Meetup - Sydney - March

RolesPlays as reusable 'components'

Page 43: AWS Meetup - Sydney - March

RolesBased on convention based on filename and directory structureGrouping of related tasks, files, handlers etcrole_name/tasks/main.ymlhandlers/main.ymlvars/main.ymlfiles/{file1.conf,file2.txt}templates/{file3.conf.j2,otherfile.j2}

Page 44: AWS Meetup - Sydney - March

Installhttp://docs.ansible.com/intro_installation.html

Page 45: AWS Meetup - Sydney - March

Documentationhttp://docs.ansible.com/