Top Banner
Todd Owen Ansible, Simplicity, and the Zen of Python
37

Ansible, Simplicity, and the Zen of Python

Aug 18, 2015

Download

Technology

toddmowen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ansible, Simplicity, and the Zen of Python

Todd Owen

Ansible, Simplicity, and the Zen of Python

Page 2: Ansible, Simplicity, and the Zen of Python

Koan 1

Page 3: Ansible, Simplicity, and the Zen of Python

master

agent

agent

MANIFESTSSL

Puppet

Page 4: Ansible, Simplicity, and the Zen of Python

for host in `cat /etc/temple_hosts` do ssh $host sudo apt-get purge puppet done

Bash

Page 5: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 3. Simple is better than complex. \ \ / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

>>> import this

Page 6: Ansible, Simplicity, and the Zen of Python

master

agent

agent

MANIFEST SSL

for host in `cat /etc/temple_hosts` do ssh $host sudo apt-get purge puppet done

Push

Pull

SIMPLE

Page 7: Ansible, Simplicity, and the Zen of Python

What is Ansible?

• IT automation tool!

• à la puppet, chef, CFEngine, salt, etc!

• Growing fast

Page 8: Ansible, Simplicity, and the Zen of Python

ThoughtWorks Tech Radar

Ansible

Page 9: Ansible, Simplicity, and the Zen of Python

Ansible is simple

SSHPLAYBOOK ansible

Page 10: Ansible, Simplicity, and the Zen of Python

Example playbook

--- - hosts: all sudo: yes tasks: - apt: name=puppet state=absent purge=yes

-i /etc/temple_hosts

Page 11: Ansible, Simplicity, and the Zen of Python

Python is simple

class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } Java

print("Hello World!") Python

Page 12: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 3. Simple is better than complex. \ \ / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

4. Complex is better than complicated. !!!!!

Page 13: Ansible, Simplicity, and the Zen of Python

Occam’s Razor

Complex:!

• many elements!

• all necessary!

Complicated:!

• introduces unnecessary elements

Page 14: Ansible, Simplicity, and the Zen of Python

Ansible Puppet

apt yum

package

apt yum

APT YUM APT YUM

module: provider:

resource type:

Complex Complicated

OS:

Page 15: Ansible, Simplicity, and the Zen of Python

Python is uncomplicated

• grp (Unix)!

• winreg (Windows)!

• “…don’t cut off access to platform capabilities or properties” (Guido van Rossum)

Page 16: Ansible, Simplicity, and the Zen of Python

Koan 2

Page 17: Ansible, Simplicity, and the Zen of Python

hall

tree

door

corridor

room

office

Page 18: Ansible, Simplicity, and the Zen of Python

templerunner.zip

src/

main/

java/

temple/

Run.java

Page 19: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 5. Flat is better than nested. \ \ / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

Page 20: Ansible, Simplicity, and the Zen of Python

Ansible: unarchive

Python: zipfile

.NET: System.IO.Compression

Page 21: Ansible, Simplicity, and the Zen of Python

Namespace

Ansible:

Python: zipfile

.NET: System.IO.Compression

unarchive

ZipFile

ZipArchive

Page 22: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 19. Namespaces are one honking great \ \ idea -- let's do more of those! / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

Page 23: Ansible, Simplicity, and the Zen of Python

Namespace

Roles: Stouts django

cchurch django

futurice django

Page 24: Ansible, Simplicity, and the Zen of Python

Koan 3

Page 25: Ansible, Simplicity, and the Zen of Python

sum_fields --delim="," tally_columns

export IFS="," !!... !

Page 26: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 2. Explicit is better than implicit. \ \ / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

Page 27: Ansible, Simplicity, and the Zen of Python

Explicit module result

tasks: - name: Verify Python 3.x is the default command: /usr/bin/python --version register: pyver failed_when: "'Python 3' not in pyver.stderr"

Page 28: Ansible, Simplicity, and the Zen of Python

Magic variable?

tasks: - name: Verify Python 3 is the default command: /usr/bin/python --version register: pyver failed_when: "'Python 3' not in res.stderr"

Page 29: Ansible, Simplicity, and the Zen of Python

Magic variable?

tasks: - name: Verify Python 3 is the default command: /usr/bin/python --version register: pyver failed_when: "'Python 3' not in res.stderr" ! - copy: dest=~/py.ver content="{{res.stderr}}"

Page 30: Ansible, Simplicity, and the Zen of Python

Ansible and Python

Similar design philosophy!

• Simple!

• Consistent!

• Easy to learn

Page 31: Ansible, Simplicity, and the Zen of Python

Ansible vision

Michael DeHaan, BDFL!

“radically simple”!

“easiest config management system to use, ever”!

— README v0.0.1

Page 32: Ansible, Simplicity, and the Zen of Python

simple less!features

simple consistent!mental model

=

Page 33: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 8. Special cases aren't special \ \ enough to break the rules. / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

Page 34: Ansible, Simplicity, and the Zen of Python

–Michael DeHaan

“We’re simplifiers. We’re seeking a whole new technical aesthetic where much of the

software industry has been adrift.”

Page 35: Ansible, Simplicity, and the Zen of Python

————————————————————————————————————————— / 1. Beautiful is better than ugly. \ \ / ————————————————————————————————————————— \ ^__^ \ (oo)\_______ (__)\ )\/\ ||————w | || ||

Page 36: Ansible, Simplicity, and the Zen of Python

Beautiful!Python

simplicity!minimalism!pragmatism

=

[email protected]!!

Analytics & Information Team, Commonwealth Bank

WE’RE HIRING!

Page 37: Ansible, Simplicity, and the Zen of Python

Image Credits !

ThoughtWorks Technology Radar! ! Copyright ThoughtWorks!

Ansible Galaxy Logo!! ! ! ! ! Copyright Ansible, Inc.!

Github Avatar!! ! ! ! ! ! ! Copyright Michael DeHaan!

All other images! ! ! ! ! ! ! Public domain

Copyright !

This work by Todd Owen is licensed under a Creative Commons Attribution 4.0 International License.!