Slide 1

Slide 1 text

Configuration & Deployment with PyCarolinas - October 21st, 2012 - Chapel Hill Michael DeHaan Sunday, October 21, 12

Slide 2

Slide 2 text

michael.dehaan@gmail.com • Writing systems management software since 2000. • IBM. Adaptec. Red Hat. Puppet Labs. rPath. • Python since 2004. • Previous projects: • cobbler.github.com (PXE, virt, pkg mirroring) • fedorahosted.org/func (predecessor to Ansible) Sunday, October 21, 12

Slide 3

Slide 3 text

UNIX PHILOSOPHY Sunday, October 21, 12

Slide 4

Slide 4 text

Project History • Started Feb, 2012 -- just 8 months ago • nearing 700 followers on github • 100+ code contributors in 8 months • ~30 contributors per month! • Diverse userbase: large .coms, hosting providers, universities, consultants, government agencies Sunday, October 21, 12

Slide 5

Slide 5 text

Many Tools In One Deployment Fabric, Capistrano Config Puppet, Chef, bcfg2 Parallel Execution Func, clones, pssh Orchestration very unique approaches Sunday, October 21, 12

Slide 6

Slide 6 text

Desirable Traits • Config & Deployment over SSH • No Extraneous PKI • Self-Bootstrapping • No Extra Daemons, No Server, Nothing To Install On Client Machines • Multi-Tier Management • Dead Simple Management Language Sunday, October 21, 12

Slide 7

Slide 7 text

Transport Options paramiko Python SSH (easy to use) ssh uses OpenSSH (Kerberos!) local suitable for use on cron pull local mode + periodic git pulls fireball Ephemeral 0mq daemon Sunday, October 21, 12

Slide 8

Slide 8 text

Architecture Sunday, October 21, 12

Slide 9

Slide 9 text

[webservers] narf.example.com poyk.example.com egad.example.com [dbservers] troz.example.com fjord.example.com zort.example.com /etc/ansible/hosts Sunday, October 21, 12

Slide 10

Slide 10 text

Sample of Core Modules... pip selinux git yum apt user service copy template file nagios virt ini_file mysql postgresql Sunday, October 21, 12

Slide 11

Slide 11 text

ansible ‘www*’ -m ping Parallel Task Execution Sunday, October 21, 12

Slide 12

Slide 12 text

ansible labmachines -a ‘/bin/foo --args 1234’ Sunday, October 21, 12

Slide 13

Slide 13 text

ansible all -m user ‘name=sauron state=absent’ Sunday, October 21, 12

Slide 14

Slide 14 text

ansible ‘www*’ -m yum -a “name=foo state=latest’ --forks 50 Sunday, October 21, 12

Slide 15

Slide 15 text

started start if not running stopped stop if running restarted restart, regardless Idempotent Resource Model example: service Sunday, October 21, 12

Slide 16

Slide 16 text

absent remove if installed present install if not installed *name=version install a specific version latest update if not at latest version Idempotent Resource Model example: yum Sunday, October 21, 12

Slide 17

Slide 17 text

Playbooks • OS Configuration • App Deployment • Release Engineering / Rolling Updates • Setup Dev Environments (ex: Vagrant) • Cowsay Integration (if installed) Sunday, October 21, 12

Slide 18

Slide 18 text

- hosts: all user: root vars: http_port: 80 max_clients: 200 tasks: - yum: name=$item state=installed with_items: - httpd - fooapp - template: src=templates/httpd.j2 dest=/etc/httpd.conf notify: - restart apache handlers: - name: restart apache service: name=apache state=restarted Playbook Example Sunday, October 21, 12

Slide 19

Slide 19 text

Python API Sunday, October 21, 12

Slide 20

Slide 20 text

import ansible.runner import sys results = ansible.runner.Runner( pattern='webservers', forks=10, module_name=‘command’, module_args='/usr/bin/uptime' ).run() Task Execution Sunday, October 21, 12

Slide 21

Slide 21 text

pb = ansible.playbook.PlayBook( playbook=playbook, host_list=options.inventory, forks=options.forks, remote_pass=sshpass, callbacks=playbook_cb, runner_callbacks=runner_cb, stats=stats, only_tags=only_tags, subset=options.subset, ) " " results = pb.run() Launching Playbooks Sunday, October 21, 12

Slide 22

Slide 22 text

def main(): module = AnsibleModule( argument_spec = dict( state=dict(default='present', choices=['present', 'absent']), name=dict(required=True), ... ) ) module.exit_json(**result) Modules (Any Language), but Python++ Sunday, October 21, 12

Slide 23

Slide 23 text

Extensible Via Plugins • callbacks (Python) • server side module code (Python) • data sources (Python) • inventory sources (any language) Sunday, October 21, 12

Slide 24

Slide 24 text

class CallbackModule(object): """ makes Ansible much more exciting on OS X. """ def on_any(self, *args, **kwargs): pass def runner_on_failed(self, host, res, ignore_errors=False): say("Failure on host %s" % host, FAILED_VOICE) def runner_on_ok(self, host, res): say("pew", LASER_VOICE) def runner_on_error(self, host, msg): pass def runner_on_skipped(self, host, item=None): say("pew", LASER_VOICE) Example: OS X Sound Effects Callback Plugin Sunday, October 21, 12

Slide 25

Slide 25 text

Some Modules We Use • multiprocessing • paramiko • subprocess (exec openssh) • pyzmq, keyczar (‘fireball mode’) • Jinja2 • JSON, YAML Sunday, October 21, 12

Slide 26

Slide 26 text

C’mon Dave, Gimme A Break • 0.9 “Dreams” - current devel • 0.8 “Cathedral” - 10/2012 • 0.7 “Panama” - 9/2012 • 0.6 “Cabo” - 8/2012 • 0.5 “Amsterdam” - 7/2012 • 0.4 “Unchained” - 5/2012 • 0.3 “Baluchitherium” - 4/2012 Sunday, October 21, 12

Slide 27

Slide 27 text

Upcoming Features • Language syntax upgrades (‘when’) • Further performance upgrades • Improved module platform support • Continued module upgrades/additions • new REST interface (Flask+Riak?) Sunday, October 21, 12

Slide 28

Slide 28 text

http://ansible.cc Sunday, October 21, 12

Slide 29

Slide 29 text

Links • http://ansible.cc • http://github.com/ansible/ansible • @laserllama • michael.dehaan@gmail.com Sunday, October 21, 12