ansible.playbook package

class ansible.playbook.Playbook(loader)[source]

Bases: object

static load(file_name, variable_manager=None, loader=None)[source]
get_loader()[source]
get_plays()[source]

Submodules

ansible.playbook.attribute module

class ansible.playbook.attribute.Attribute(isa=None, private=False, default=None, required=False, listof=None, priority=0, class_type=None, always_post_validate=False)[source]

Bases: object

class ansible.playbook.attribute.FieldAttribute(isa=None, private=False, default=None, required=False, listof=None, priority=0, class_type=None, always_post_validate=False)[source]

Bases: ansible.playbook.attribute.Attribute

ansible.playbook.base module

class ansible.playbook.base.Base[source]

Bases: object

DEPRECATED_ATTRIBUTES = ['sudo', 'sudo_user', 'sudo_pass', 'sudo_exe', 'sudo_flags', 'su', 'su_user', 'su_pass', 'su_exe', 'su_flags']
preprocess_data(ds)[source]

infrequently used method to do some pre-processing of legacy terms

load_data(ds, variable_manager=None, loader=None)[source]

walk the input datastructure and assign any values

get_ds()[source]
get_loader()[source]
get_variable_manager()[source]
validate(all_vars={})[source]

validation that is done at parse time, not load time

copy()[source]

Create a copy of this object and return it.

post_validate(templar)[source]

we can’t tell that everything is of the right type until we have all the variables. Run basic types (from isa) as well as any _post_validate_<foo> functions.

serialize()[source]

Serializes the object derived from the base object into a dictionary of values. This only serializes the field attributes for the object, so this may need to be overridden for any classes which wish to add additional items not stored as field attributes.

deserialize(data)[source]

Given a dictionary of values, load up the field attributes for this object. As with serialize(), if there are any non-field attribute data members, this method will need to be overridden and extended.

ansible.playbook.become module

class ansible.playbook.become.Become[source]

Bases: object

set_become_defaults(become, become_method, become_user)[source]

if we are becoming someone else, but some fields are unset, make sure they’re initialized to the default config values

ansible.playbook.block module

class ansible.playbook.block.Block(play=None, parent_block=None, role=None, task_include=None, use_handlers=False, implicit=False)[source]

Bases: ansible.playbook.base.Base, ansible.playbook.become.Become, ansible.playbook.conditional.Conditional, ansible.playbook.taggable.Taggable

get_vars()[source]

Blocks do not store variables directly, however they may be a member of a role or task include which does, so return those if present.

static load(data, play=None, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None)[source]
static is_block(ds)[source]
preprocess_data(ds)[source]

If a simple task is given, an implicit block for that single task is created, which goes in the main portion of the block

get_dep_chain()[source]
copy(exclude_parent=False, exclude_tasks=False)[source]
serialize()[source]

Override of the default serialize method, since when we’re serializing a task we don’t want to include the attribute list of tasks.

deserialize(data)[source]

Override of the default deserialize method, to match the above overridden serialize method

evaluate_conditional(templar, all_vars)[source]
set_loader(loader)[source]
filter_tagged_tasks(play_context, all_vars)[source]

Creates a new block, with task lists filtered based on the tags contained within the play_context object.

has_tasks()[source]

ansible.playbook.conditional module

class ansible.playbook.conditional.Conditional(loader=None)[source]

Bases: object

This is a mix-in class, to be used with Base to allow the object to be run conditionally when a condition is met or skipped.

evaluate_conditional(templar, all_vars)[source]

Loops through the conditionals set on this object, returning False if any of them evaluate as such.

ansible.playbook.handler module

class ansible.playbook.handler.Handler(block=None, role=None, task_include=None)[source]

Bases: ansible.playbook.task.Task

__repr__()[source]

returns a human readable representation of the handler

static load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None)[source]
flag_for_host(host)[source]
has_triggered(host)[source]
serialize()[source]

ansible.playbook.handler_task_include module

class ansible.playbook.handler_task_include.HandlerTaskInclude(block=None, role=None, task_include=None)[source]

Bases: ansible.playbook.handler.Handler, ansible.playbook.task_include.TaskInclude

static load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None)[source]

ansible.playbook.helpers module

ansible.playbook.helpers.load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None)[source]

Given a list of mixed task/block data (parsed from YAML), return a list of Block() objects, where implicit blocks are created for each bare Task.

ansible.playbook.helpers.load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None)[source]

Given a list of task datastructures (parsed from YAML), return a list of Task() or TaskInclude() objects.

ansible.playbook.helpers.load_list_of_roles(ds, play, current_role_path=None, variable_manager=None, loader=None)[source]

Loads and returns a list of RoleInclude objects from the datastructure list of role definitions

ansible.playbook.included_file module

class ansible.playbook.included_file.IncludedFile(filename, args, task)[source]

Bases: object

add_host(host)[source]
static process_include_results(results, tqm, iterator, inventory, loader, variable_manager)[source]

ansible.playbook.loop_control module

class ansible.playbook.loop_control.LoopControl[source]

Bases: ansible.playbook.base.Base

static load(data, variable_manager=None, loader=None)[source]

ansible.playbook.play module

class ansible.playbook.play.Play[source]

Bases: ansible.playbook.base.Base, ansible.playbook.taggable.Taggable, ansible.playbook.become.Become

A play is a language feature that represents a list of roles and/or task/handler blocks to execute on a given set of hosts.

Usage:

Play.load(datastructure) -> Play Play.something(...)
get_name()[source]

return the name of the Play

static load(data, variable_manager=None, loader=None)[source]
preprocess_data(ds)[source]

Adjusts play datastructure to cleanup old/legacy items

compile_roles_handlers()[source]

Handles the role handler compilation step, returning a flat list of Handlers This is done for all roles in the Play.

compile()[source]

Compiles and returns the task list for this play, compiled from the roles (which are themselves compiled recursively) and/or the list of tasks specified in the play.

get_vars()[source]
get_vars_files()[source]
get_handlers()[source]
get_roles()[source]
get_tasks()[source]
serialize()[source]
deserialize(data)[source]
copy()[source]

ansible.playbook.play_context module

class ansible.playbook.play_context.PlayContext(play=None, options=None, passwords=None, connection_lockfd=None)[source]

Bases: ansible.playbook.base.Base

This class is used to consolidate the connection information for hosts in a play and child tasks, where the task may override some connection/authentication information.

set_play(play)[source]

Configures this connection information instance with data from the play class.

set_options(options)[source]

Configures this connection information instance with data from options specified by the user on the command line. These have a lower precedence than those set on the play or host.

set_task_and_variable_override(task, variables, templar)[source]

Sets attributes from the task if they are set, which will override those from the play.

make_become_cmd(cmd, executable=None)[source]

helper function to create privilege escalation commands

update_vars(variables)[source]

Adds ‘magic’ variables relating to connections to the variable dictionary provided. In case users need to access from the play, this is a legacy from runner.

ansible.playbook.playbook_include module

class ansible.playbook.playbook_include.PlaybookInclude[source]

Bases: ansible.playbook.base.Base, ansible.playbook.conditional.Conditional, ansible.playbook.taggable.Taggable

static load(data, basedir, variable_manager=None, loader=None)[source]
load_data(ds, basedir, variable_manager=None, loader=None)[source]

Overrides the base load_data(), as we’re actually going to return a new Playbook() object rather than a PlaybookInclude object

preprocess_data(ds)[source]

Regorganizes the data for a PlaybookInclude datastructure to line up with what we expect the proper attributes to be

ansible.playbook.taggable module

class ansible.playbook.taggable.Taggable[source]

Bases: object

untagged = frozenset(['untagged'])
evaluate_tags(only_tags, skip_tags, all_vars)[source]

this checks if the current item should be executed depending on tag options

ansible.playbook.task module

class ansible.playbook.task.Task(block=None, role=None, task_include=None)[source]

Bases: ansible.playbook.base.Base, ansible.playbook.conditional.Conditional, ansible.playbook.taggable.Taggable, ansible.playbook.become.Become

A task is a language feature that represents a call to a module, with given arguments and other parameters. A handler is a subclass of a task.

Usage:

Task.load(datastructure) -> Task Task.something(...)
get_path()[source]

return the absolute path of the task with its line number

get_name()[source]

return the name of the task

static load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None)[source]
__repr__()[source]

returns a human readable representation of the task

preprocess_data(ds)[source]

tasks are especially complex arguments so need pre-processing. keep it short.

post_validate(templar)[source]

Override of base class post_validate, to also do final validation on the block and task include (if any) to which this task belongs.

get_vars()[source]
get_include_params()[source]
copy(exclude_block=False)[source]
serialize()[source]
deserialize(data)[source]
evaluate_conditional(templar, all_vars)[source]
set_loader(loader)[source]

Sets the loader on this object and recursively on parent, child objects. This is used primarily after the Task has been serialized/deserialized, which does not preserve the loader.

ansible.playbook.task_include module

class ansible.playbook.task_include.TaskInclude(block=None, role=None, task_include=None)[source]

Bases: ansible.playbook.task.Task

A task include is derived from a regular task to handle the special circumstances related to the - include: ... task.

static load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None)[source]
get_vars()[source]

We override the parent Task() classes get_vars here because we need to include the args of the include into the vars as they are params to the included tasks.

ansible.playbook.vars module

ansible.playbook.vars_file module