Linchpin API and Context Modules¶
The linchpin module provides the base API for managing LinchPin, Ansible, and other useful aspects for provisioning.
-
class
linchpin.
LinchpinAPI
(ctx)[source]¶ -
bind_to_hook_state
(callback)[source]¶ Function used by LinchpinHooksclass to add callbacks
Parameters: callback – callback function
-
do_action
(provision_data, action='up', run_id=None, tx_id=None)[source]¶ This function takes provision_data, and executes the given action for each target within the provision_data disctionary.
Parameters: provision_data – PinFile data as a dictionary, with target information
Parameters: - action – Action taken (up, destroy, etc). (Default: up)
- run_id – Provided run_id to duplicate/destroy (Default: None)
- tx_id – Provided tx_id to duplicate/destroy (Default: None)
-
get_cfg
(section=None, key=None, default=None)[source]¶ Get cfgs value(s) by section and/or key, or the whole cfgs object
Parameters: - section – section from ini-style config file
- key – key to get from config file, within section
- default – default value to return if nothing is found.
-
get_evar
(key=None, default=None)[source]¶ Get the current evars (extra_vars)
Parameters: - key – key to use
- default – default value to return if nothing is found
(default: None)
-
get_pf_data_from_rundb
(targets, run_id=None, tx_id=None)[source]¶ This function takes the action and provision_data, returns the pinfile data
Parameters: - targets – A list of targets for which to get the data
- targets – Tuple of target(s) for which to gather data.
- run_id – run_id associated with target (Default: None)
- tx_id – tx_id for which to gather data (Default: None)
-
get_run_data
(tx_id, fields, targets=())[source]¶ Returns the RunDB for data from a specified field given a tx_id. The fields consist of the major sections in the RunDB (target view only). Those fields are action, start, end, inputs, outputs, uhash, and rc.
Parameters: - tx_id – tx_id to search
- fields – Tuple of fields to retrieve for each record requested.
- targets – Tuple of targets to search from within the tx_ids
-
hook_state
¶ getter function for hook_state property of the API object
-
set_cfg
(section, key, value)[source]¶ Set a value in cfgs. Does not persist into a file, only during the current execution.
Parameters: - section – section within ini-style config file
- key – key to use
- value – value to set into section within config file
-
-
class
linchpin.context.
LinchpinContext
[source]¶ LinchpinContext object, which will be used to manage the cli, and load the configuration file.
-
get_cfg
(section=None, key=None, default=None)[source]¶ Get cfgs value(s) by section and/or key, or the whole cfgs object
Parameters: - section – section from ini-style config file
- key – key to get from config file, within section
- default – default value to return if nothing is found.
Does not apply if section is not provided.
-
get_evar
(key=None, default=None)[source]¶ Get the current evars (extra_vars)
Parameters: - key – key to use
- default – default value to return if nothing is found
(default: None)
-
load_config
(search_path=None)[source]¶ Update self.cfgs from the linchpin configuration file (linchpin.conf).
NOTE: Must be implemented by a subclass
-
load_global_evars
()[source]¶ Instantiate the evars variable, then load the variables from the ‘evars’ section in linchpin.conf. This will then be passed to invoke_linchpin, which passes them to the Ansible playbook as needed.
-
log
(msg, **kwargs)[source]¶ Logs a message to a logfile
Parameters: - msg – message to output to log
- level – keyword argument defining the log level
-
log_state
(msg)[source]¶ Logs nothing, just calls pass
Attention
state messages need to be implemented in a subclass
-
set_cfg
(section, key, value)[source]¶ Set a value in cfgs. Does not persist into a file, only during the current execution.
Parameters: - section – section within ini-style config file
- key – key to use
- value – value to set into section within config file
-
-
linchpin.ansible_runner.
ansible_runner
(playbook_path, module_path, extra_vars, inventory_src='localhost', verbosity=1, console=True)[source]¶ Uses the Ansible API code to invoke the specified linchpin playbook :param playbook: Which ansible playbook to run (default: ‘up’) :param console: Whether to display the ansible console (default: True)
-
linchpin.ansible_runner.
ansible_runner_24x
(playbook_path, extra_vars, options=None, inventory_src='localhost', console=True)[source]¶
-
linchpin.ansible_runner.
ansible_runner_2x
(playbook_path, extra_vars, options=None, inventory_src='localhost', console=True)[source]¶