simple_automation.inventory.Inventory

class simple_automation.inventory.Inventory(manager)

Bases: object

An inventory is a collection of definitions for vaults, tasks, global variables, hosts and groups. It also defines what tasks are run for each host.

Methods

register_globals

This function will be executed when your inventory should define its global variables.

register_inventory

This function will be executed when your inventory should define the hosts and groups.

register_tasks

This function will be executed when your inventory should define the tasks it want’s to run.

register_vaults

This function will be executed when your inventory should define the vaults it want’s to access.

run

This function is the default inventory script that will be executed for each host context, and is your main customization point.

Attributes

tasks

A list of task classes that should be registered to this inventory.

register_globals()

This function will be executed when your inventory should define its global variables. Use self.manager.set() to define them.

register_inventory()

This function will be executed when your inventory should define the hosts and groups. Use self.manager.add_host() and self.manager.add_group() to define them.

register_tasks()

This function will be executed when your inventory should define the tasks it want’s to run. By default, this function will register all tasks given in the list self.tasks.

You can register tasks manually via a call to self.manager.add_task(). You may either save the return value of this function, and use ret.exec(context) to execute the task, or use the convenience method context.run_task(TaskClass).

register_vaults()

This function will be executed when your inventory should define the vaults it want’s to access. Do this via a call to self.manager.add_vault(). Also remember to save the return value of this function, which will be a vault object you can later use to access stored values.

run(context)

This function is the default inventory script that will be executed for each host context, and is your main customization point. Here you can build your logic of what tasks to execute for a given host.

It is a good idea to split this up into several functions, because then you will be able to call those functions separately by selecting them via the --scripts command line option.

tasks = []

A list of task classes that should be registered to this inventory.