V2 and beyond

30
ANSIBLE UPDATE V2 AND BEYOND JAMES CAMMARATA

Transcript of V2 and beyond

Page 1: V2 and beyond

ANSIBLE UPDATEV2 AND BEYOND

JAMES CAMMARATA

Page 2: V2 and beyond

ABOUT MEDirector of Ansible Core Engineering

Started contributing to Cobbler in September of 2008, and tookover the project leadership in 2010

Joined Ansible in July, 2013

Page 3: V2 and beyond

WHY V2?

Page 4: V2 and beyond

TECHNICAL DEBTAnsible has grown organically at a very rapid rate for 3+ years.Some early design descisions have had additional featuresbolted on without concern for the overall system architecture.It was getting to the point where it was difficult to fix bugsand/or add new features without things breaking inunexpected ways.Difficulty of testing, especially in terms of python unit tests, didnot help.

Page 5: V2 and beyond

NEW FEATURES IN V2:

Page 6: V2 and beyond

IMPROVED ERROR MESSAGESPlaybook errors not related to syntax will (in most cases) stillshow the file along with the line and column where the error

occurred.

Page 7: V2 and beyond

IMPROVED ERROR EXAMPLE:ERROR! no action detected in task

The error appears to have been in '/path/to/bad/playbook/site.yml':line 4, column 16, but may be elsewhere in the file depending on theexact syntax problem.

The offending line appears to be:

tasks: - bad_module: ̂ here

Page 8: V2 and beyond

BLOCKSProvides a method for catching errors during task execution,as well as an option to always execute some set of tasksregardless of whether an exception occurred or not.Allows for easier grouping of related tasks.

Page 9: V2 and beyond

BLOCK EXAMPLE:tasks: - block: - command: /bin/false - debug: msg="you shouldn't see me" rescue: - debug: msg="this is the rescue" - command: /bin/false - debug: msg="you shouldn't see this either" always: - debug: msg="this is the always block, it will always be seen"

Page 10: V2 and beyond

NESTED BLOCK EXAMPLE:tasks: - block: - block: - block: - block: - debug: msg="Yes, this really works (but try not to do it too much)"

Page 11: V2 and beyond

BLOCKS MAKE GROUPING RELATED TASKS EASIERtasks:- block: - debug: msg="task 1" - debug: msg="task 2" when: foo != "some value" tags: - do_tasks

Page 12: V2 and beyond

EXECUTION STRATEGY PLUGINSAllows changes in the way tasks are executed:

linear - traditional Ansible, which waits for all hosts tocomplete a task before continuingfree - allows each host to process tasks as fast as possible,without waiting for other hostsAnd anything else people can conceive - just write a new pluginfor it!

Page 13: V2 and beyond

STRATEGY EXAMPLE:- hosts: all gather_facts: false strategy: free vars: ... vars_files: ... tasks: ...

Page 14: V2 and beyond

EXECUTION-TIME EVALUATION OF INCLUDETASKS

Previously, include statements acted like pre-processorstatements and were evaluated/expanded before any tasks

started running.

Should allow the return use of include + with* actions.

Page 15: V2 and beyond

INCLUDE + WITH EXAMPLE:- hosts: all gather_facts: false tasks: - include: foo.yml some_var={{item}} with_items: - a - b - c

Page 16: V2 and beyond

INCLUDE + WITH EXAMPLE #2:- hosts: all gather_facts: false tasks: - include: "{{inventory_hostname}}.yml some_var={{item}}"

Page 17: V2 and beyond

EXTENDED INHERITENCE OF BLOCKS/ROLESValues like `become*` and others are now settable on blocks and

roles, which are then inherited by all tasks contained within.

Page 18: V2 and beyond

INHERITENCE EXAMPLE- hosts: all gather_facts: false remote_user: testing roles: - { role: foo, become_user: root } tasks: - block - command: whoami - command: /do/something/privileged - stat: path=/root/.ssh/id_rsa become_user: root

Page 19: V2 and beyond

IMPROVED VARIABLE MANAGEMENTA new class (VariableManager) controls the order and source of

variables to avoid flattening things too early.

Playbook objects now use a `post_validate` method, whichtemplates all fields in one shot, as opposed to the piece-meal way

we currently template field values.

Page 20: V2 and beyond

BETTER USE OF OOPMore classes, with an emphasis on each class doing one thing

only.

More use of inheritance, especially in the plugin systems.

Well defined interactions between classes.

End-goal is better ability to write unit tests.

Page 21: V2 and beyond

WHAT WILL BREAK?

Page 22: V2 and beyond

PLAYBOOKSNothing. We are aiming for 100% backwards-compatibility.

Page 23: V2 and beyond

INTERNAL APISPlugin APIs are changing. Connection, action, and some others

will be different.

We plan on writing a transition classes and a guide for authors ofplugins, to make it easier to move them to be compatible with V2.

Page 24: V2 and beyond

EXAMPLE TRANSITIONAL CLASSfrom distutils.version import LooseVersionfrom ansible import __version__ as __ansible_version__class LookupModule(object): def __new__(class_name, *args, **kwargs): if LooseVersion(__ansible_version__) < LooseVersion("2.0"): from ansible import utils, errors class LookupModuleV1(object): def __init__(self, basedir, *args, **kwargs): self.basedir = basedir def run(self, terms, inject=None, **kwargs): ... else: from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase class LookupModuleV2(LookupBase): def run(self, terms, variables=None, **kwargs): ...

Page 25: V2 and beyond

V2 STATUS TODAY

Page 26: V2 and beyond

Live in the devel branch as of June 1st, 2015

Expected official release of Ansible 2.0 is early to mid-July, 2015

Page 27: V2 and beyond

UPCOMING MODULESCHANGES

Page 28: V2 and beyond

The 'extras' modules will be come another package to beinstalled. Installations from source will still see it as a submodule.

The 'core' modules repository will be going away, and will againbe part of the main ansible/ansible repository.

Page 29: V2 and beyond

QUESTIONS?

Page 30: V2 and beyond

THANKS!