Slide 1

Slide 1 text

Pyventory for Ansible Serge Matveenko github.com/lig twitter.com/lig1

Slide 2

Slide 2 text

What is Ansible? Ansible is an IT automation tool www.ansible.com docs.ansible.com/ansible

Slide 3

Slide 3 text

A classic Ansible Inventory ● .ini files for groups and hosts (YAML is also possible now) ● .yml files for groups configuration all in one dir ● .yml files for hosts configuration all in another dir ● Messy inheritance ● Messy mixins ● No cross-referencing

Slide 4

Slide 4 text

A classic Ansible Inventory [atlanta] host1 host2 [raleigh] host2 host3 [southeast:children] atlanta raleigh [southeast:vars] some_server=foo.southeast.example.com halon_system_timeout=30 self_destruct_countdown=60 escape_pods=2 [usa:children] southeast northeast southwest northwest all: children: usa: children: southeast: children: atlanta: hosts: host1: host2: raleigh: hosts: host2: host3: vars: some_server: foo.southeast.example.com halon_system_timeout: 30 self_destruct_countdown: 60 escape_pods: 2 northeast: northwest: southwest:

Slide 5

Slide 5 text

Requirements ● Multiple inheritance & mixins ● Required attributes ● Calculated attributes ● Cross-references between assets ● Easy to extend ● Autocomplete in IDE

Slide 6

Slide 6 text

Pyventory

Slide 7

Slide 7 text

Pyventory #!/usr/bin/env python from pyventory import Asset, ansible_inventory class All(Asset): run_tests = False use_redis = False redis_host = 'localhost' minify = False version = 'develop' class Staging(All): run_tests = True staging = Staging() ansible_inventory(locals())

Slide 8

Slide 8 text

More Pyventory #!/usr/bin/env python from pyventory import ansible_inventory from inventory import * develop = DevelopHost() develop_sidebranch = DevelopHost( ansible_host='sidebranch_hostname', version='sidebranch_name') staging = StagingHost() prod_backend1 = ProdBackEnd(num=1) # app001.prod.dom prod_backend2 = ProdBackEnd(num=2) # app002.prod.dom prod_frontend1 = ProdFrontEnd(num=1) # www001.prod.dom prod_frontend2 = ProdFrontEnd(num=2) # www002.prod.dom ansible_inventory(locals(), indent=4) class DevelopHost(Staging, BackEnd, FrontEnd): ansible_host = 'develop_hostname' version = 'develop' class StagingHost(Staging, BackEnd, FrontEnd): ansible_host = 'master_hostname' version = 'master' class ProdBackEnd(Production, BackEnd): redis_host = 'prod_redis_hostname' ansible_hostname = 'app{num:03}.prod.dom' class ProdFrontEnd(Production, FrontEnd): ansible_hostname = 'www{num:03}.prod.dom'

Slide 9

Slide 9 text

Playbook - hosts: BackEnd roles: - role: acme/back - hosts: FrontEnd roles: - role: acme/front

Slide 10

Slide 10 text

Planning ● Terraform integration ● Secure Vault support ● Complex attributes merging strategy

Slide 11

Slide 11 text

Questions? Use, star, fork Pyventory github.com/lig/pyventory Follow me github.com/lig twitter.com/lig1