nsbl package¶
Submodules¶
nsbl.ansible_extensions module¶
-
class
nsbl.ansible_extensions.
AnsibleFilterExtension
(environment)[source]¶ Bases:
jinja2.ext.Extension
-
identifier
= 'nsbl.ansible_extensions.AnsibleFilterExtension'¶
-
-
nsbl.ansible_extensions.
utils
¶
nsbl.defaults module¶
nsbl.exceptions module¶
nsbl.inventory module¶
-
class
nsbl.inventory.
NsblInventory
(**init_params)[source]¶ Bases:
frkl.callbacks.FrklCallback
-
static
create
(config, default_env_type=u'group', pre_chain=None)[source]¶ Convenience method to create a NsblInventory object out of the configs and a few optional parameters.
Parameters: Returns: the inventory object, already ‘processed’
Return type:
-
extract_vars
(inventory_dir)[source]¶ Writes a folder structure with ‘group_vars’ and ‘host_vars’ folders into the target directory.
Parameters: inventory_dir (str) – the directory the inventory should be written to
-
get_inventory_config_string
()[source]¶ Returns a string that can be used to write an ansible hosts file, including hosts, groups and child-groups.
-
get_vars
(env_name)[source]¶ Returns all variables for the environment with the specified name.
First tries whether the name matches a group, then tries hosts.
Parameters: env_name (str) – the name of the group or host Returns: the variables for the environment Return type: dict
-
host
(host)[source]¶ Returns the inventory information for the specified host, in the format required for ansible dynamic inventories.
Parameters: host (str) – the name of the host Returns: dict: all inventory information for this host
-
list
()[source]¶ Lists all groups in the format that is required for ansible dynamic inventories.
More info: https://docs.ansible.com/ansible/intro_dynamic_inventory.html, http://docs.ansible.com/ansible/dev_guide/developing_inventory.html
Returns: dict: a dict containing all information about all hosts/groups
-
write_inventory_file_or_script
(inventory_dir, extract_vars=False, relative_paths=True)[source]¶ Writes an ansible hosts file or dynamic inventory script into the provided directory.
Writing a dynamic inventory script is not implemented yet.
Parameters: - inventory_dir (str) – the target directory
- extract_vars (bool) – whether to extract all vars (True, default) or write a dynamic inventory script
- relative_paths (bool) – only important for when writing dynamic inventory scripts, makes the paths in the script relative to the ansible environment root so its easily copy-able
-
static
-
class
nsbl.inventory.
WrapTasksIntoHostsProcessor
(init_params=None)[source]¶ Bases:
frkl.processors.ConfigProcessor
Wraps a list of tasks into a localhost environment.
Convenience processor to not have to do this manually, keeps configuration files minimal and sweet.
-
class
nsbl.inventory.
WrapTasksIntoLocalhostEnvProcessor
(init_params=None)[source]¶ Bases:
frkl.processors.ConfigProcessor
Wraps a list of tasks into a localhost environment.
Convenience processor to not have to do this manually, keeps configuration files minimal and sweet.
nsbl.inventory_cli module¶
nsbl.nsbl module¶
-
class
nsbl.nsbl.
Nsbl
(config, base_path=None, context=None, default_env_type=u'group', additional_files=None)[source]¶ Bases:
object
Holds and parses configuration to generate Ansible task lists and inventories.
Parameters: - config (list) – a list of configuration items
- base_path (str) – the base path to use for relative task list imports etc.
- nsbl_context (NsblContext) – the context for this environment
- default_env_type (str) – the type a environment is if it is not explicitely specified, either ENV_TYPE_HOST or ENV_TYPE_GROUP
- additional_files (dict) – a dict of additional files to copy into the Ansible environment
- allow_external_roles (bool) – whether to allow the downloading of external roles
-
render
(env_dir, global_vars=None, extract_vars=True, force=False, ask_become_pass=None, password=None, secure_vars=None, ansible_args=u'', callback=u'default', force_update_roles=False, add_timestamp_to_env=False, add_symlink_to_env=False, extra_paths=u'')[source]¶ Creates the ansible environment in the folder provided.
Parameters: - env_dir (str) – the folder where the environment should be created
- global_vars (dict) – vars to be rendered as global on top of a playbook
- extract_vars (bool) – whether to extract a hostvars and groupvars directory for the inventory (True), or render a dynamic inventory script for the environment (default, True) – Not supported at the moment
- force (bool) – overwrite environment if already present at the specified location, use with caution because this might delete an important folder if you get the ‘target’ dir wrong
- ask_become_pass (bool) – whether to include the ‘–ask-become-pass’ arg to the ansible-playbook call
- password (str) – if provided, it will be used instead of asking for a password
- secure_vars (dict) – vars to keep in a vault (not implemented yet)
- ansible_args (str) – parameters to give to ansible-playbook (like: “-vvv”)
- callback (str) – name of the callback to use, default: nsbl_internal
- force_update_roles (bool) – whether to overwrite external roles that were already downloaded
- add_timestamp_to_env (bool) – whether to add a timestamp to the env_dir – useful for when this is called from other programs (e.g. freckles)
- add_symlink_to_env (bool) – whether to add a symlink to the current env from a fixed location (useful to archive all runs/logs)
- extra_paths (str) – a colon-separated string of extra paths to be exported before the ansible playbook run
nsbl.nsbl_tasklist module¶
-
class
nsbl.nsbl_tasklist.
AugmentingTaskProcessor
(**init_params)[source]¶ Bases:
frkl.processors.ConfigProcessor
Processor to augment a basic task list.
This will augment tasks that have a ‘name’ property which can be found in the task aliases list with the content of this task alias entry. Existing task properties won’t be overwritten.
This will also make sure that the task description has a ‘meta/task-name’ and ‘vars’ key/value pair.
-
class
nsbl.nsbl_tasklist.
NsblContext
(allow_external_roles=None, allow_external_tasklists=None, **kwargs)[source]¶ Bases:
frkl.frklist.FrklistContext
-
class
nsbl.nsbl_tasklist.
NsblTasklist
(tasklist, context=None, meta=None, vars=None)[source]¶ Bases:
frkl.frklist.Frklist
-
ensure_freckles_task_list_format
(task_list)[source]¶ Make sure the task list is in ‘freckles’ format, if not, convert and add additional task file.
Parameters: - task_list (list) – the task list
- env_id – the id of the environment (used to calculate the variable name)
- task_list_id – the id of the task_list inside the environment (used to calculate the variable name)
Returns: tuple in the form of (final_task_list, external_files_dict)
Return type:
-
fill_task_type
(task_item)[source]¶ Utility method to guess the type of a task and fill in all necessary properties.
Parameters: task_item (dict) – the task item
-
nsbl.output module¶
-
class
nsbl.output.
ClickStdOutput
(display_sub_tasks=True, display_skipped_tasks=True, display_unchanged_tasks=True, display_ignore_tasks=[])[source]¶ Bases:
object
-
class
nsbl.output.
NsblLogCallbackAdapter
(lookup_dict, display_sub_tasks=True, display_skipped_tasks=True, display_unchanged_tasks=True, display_ignore_tasks=[])[source]¶ Bases:
object
nsbl.role_utils module¶
-
nsbl.role_utils.
calculate_role_repos
(role_repos)[source]¶ Utility method to calculate which role repos to use.
Role repos are folders containing ansible roles, and an (optional) task description file which is used to translate task-names in a task config file into roles or ansible tasks.
Parameters: role_repos (list) – a string or list of strings of local folders containing ansible roles Returns: a list of all local role repos to be used Return type: list
nsbl.runner module¶
-
class
nsbl.runner.
NsblRunner
(nsbl)[source]¶ Bases:
object
-
run
(target, global_vars=None, force=True, ansible_args=u'', ask_become_pass=None, password=None, secure_vars=None, callback=None, add_timestamp_to_env=False, add_symlink_to_env=False, no_run=False, display_sub_tasks=True, display_skipped_tasks=True, display_ignore_tasks=[], pre_run_callback=None, extra_paths=u'')[source]¶ Starts the ansible run, executing all generated playbooks.
By default the ‘nsbl_internal’ ansible callback is used, which outputs easier to read outputs/results. You can, however, also use the callbacks that come with ansible, like ‘default’, ‘skippy’, etc.
Parameters: - target (str) – the target directory where the ansible environment should be rendered
- global_vars (dict) – vars to be rendered on top of each playbook
- force (bool) – whether to overwrite potentially existing files at the target (most likely an old rendered ansible environment)
- ansible_args (str) – verbosity arguments to ansible-playbook command
- ask_become_pass (bool) – whether to include the ‘–ask-become-pass’ arg to the ansible-playbook call
- password (str) – if provided, it will be used instead of asking for a password
- secure_vars (dict) – other vars to keep secure, not implemented yet
- callback (str) – the callback to use for the ansible run. default is ‘default’
- add_timestamp_to_env (bool) – whether to append a timestamp to the run directory (default: False)
- add_symlink_to_env (str) – whether to add a symlink to the run directory (will be deleted if exists already and force is specified) - default: False, otherwise path to symlink
- no_run (bool) – whether to only render the environment, but not run it
- display_sub_tasks (bool) – whether to display subtasks in the output (not applicable for all callbacks)
- display_skipped_tasks (bool) – whether to display skipped tasks in the output (not applicable for all callbacks)
- display_ignore_tasks (list) – a list of strings that indicate task titles that should be ignored when displaying the task log (using the default nsbl output plugin – this is ignored with other output callbacks)
- pre_run_callback (function) – a callback to execute after the environment is rendered, but before the run is kicked off
- extra_paths (str) – a colon-separated of extra paths that should be exported for the nsbl run
Returns: the parameters of the run
Return type:
-
nsbl.task_alias_utils module¶
-
class
nsbl.task_alias_utils.
TaskAliasLucifier
(**kwargs)[source]¶ Bases:
luci.lucify.Lucifier
Class to read and merge task aliases into a single dictionary.
This can read both directories and files. If you add a directory dictlet, it will find and read all files called ‘task-aliases.yml’ recursively under that folder. It is not allowed to for multiple ‘task-aliases.yml’ files to contain the same alias key (with different values) as that would result in unpredictable behaviour depending on which file is read first.
If the path added is a file, it can be named anything, but needs to be in yaml format.
In both cases, the yaml files need to contain a single dictionary with the alias as key, and a metadata dict as value.
-
process_dictlet
(metadata, dictlet_details=None)[source]¶ The main method implemented by a lucifier, it executes the task it is written for, using the metadata accrued as configuration.
Depending on the lucifier, this may return a string, an object, or nothing (and just prints out text to stdout).
Parameters: - metadata – the metadata to process
- dictlet_details – metadata about the dictlet itself
Returns: the new (processed) metadata
Return type:
-
-
nsbl.task_alias_utils.
assemble_task_aliases
(paths)[source]¶ Helper method to assemble one task-alias dictionary from a list of paths.
Check
TaskAliasLucifier
for more details.Parameters: paths (list) – a list of paths to directories or files Returns: the (merged) task aliases Return type: dict
-
nsbl.task_alias_utils.
calculate_task_aliases
(task_alias_files_or_repos, add_upper_case_versions=True)[source]¶ Utility method to calculate which task descriptions to use.
Task descriptions are yaml files that translate task-names in a task config into roles or ansible tasks, optionally with extra default parameters.
If additional role_repos are provided, we will check whether each of them contains a file with the value of TASK_DESC_DEFAULT_FILENAME. If so, those will be added to the beginning of the resulting list.
Parameters: Returns: a list of dicts of all task description configs to be used
Return type:
nsbl.tasklist_utils module¶
-
nsbl.tasklist_utils.
get_import_task_item
(task_list_name)[source]¶ Small helper toget the task item for importing a task list.