Save 37% off PRO during our Black Friday Sale! »

Pyventory for Ansible

Pyventory for Ansible

A brief "dive in" for Pyventory project — Ansible Inventory implementation which uses Python syntax.

200442040b9d038626d92d408f499642?s=128

Serge Matveenko

December 12, 2017
Tweet

Transcript

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

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

    docs.ansible.com/ansible
  3. 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
  4. 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:
  5. Requirements • Multiple inheritance & mixins • Required attributes •

    Calculated attributes • Cross-references between assets • Easy to extend • Autocomplete in IDE
  6. Pyventory

  7. 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())
  8. 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'
  9. Playbook - hosts: BackEnd roles: - role: acme/back - hosts:

    FrontEnd roles: - role: acme/front
  10. Planning • Terraform integration • Secure Vault support • Complex

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