Exemplo n.º 1
0
    def __init__(self,
                 resource,
                 options,
                 name='adhoc',
                 callback=None,
                 job_id=None):
        if type(resource) == dict:
            self.resource = json.dumps(resource)
        else:
            self.resource = resource

        self.job_id = job_id
        self.display = Display()
        self.inventory = None
        self.name = name
        self.variable_manager = None
        self.passwords = None
        self.callback = callback or CallbackModule(job_id=job_id)
        self.results_raw = {}
        self.loader = DataLoader()
        self.options = None
        self.get_options(options, name)
        context.CLIARGS = CLIArgs(self.options)
        self.passwords = options.get('vault_pass') or {}
        self.inventory = HostsManager(loader=self.loader,
                                      sources=self.resource)
        self.variable_manager = VariableManager(loader=self.loader,
                                                inventory=self.inventory)
        verbosity = options.get('verbosity', 0)
        display.verbosity = verbosity
Exemplo n.º 2
0
    def __init__(self, args, options=None):
        super().__init__(args)
        self.args = args if type(args) == list else [args]
        self.plugin_list = set()
        options_dict = default_options
        if options:
            options_dict.update(options)

        self.options = options_dict
        context.CLIARGS = CLIArgs(self.options)
Exemplo n.º 3
0
def _init_global_context(cli_args):
    """Initialize the global context objects"""
    context.CLIARGS = CLIArgs.from_options(cli_args)
Exemplo n.º 4
0
 def update_context_args(self, options):
     self.options = self.options.update(options)
     context.CLIARGS = CLIArgs(self.options)
Exemplo n.º 5
0
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

"""
Context of the running Ansible.

In the future we *may* create Context objects to allow running multiple Ansible plays in parallel
with different contexts but that is currently out of scope as the Ansible library is just for
running the ansible command line tools.

These APIs are still in flux so do not use them unless you are willing to update them with every Ansible release
"""

from ansible.utils.context_objects import CLIArgs, GlobalCLIArgs


__all__ = ('CLIARGS',)

# Note: this is not the singleton version.  The Singleton is only created once the program has
# actually parsed the args
CLIARGS = CLIArgs({})


# This should be called immediately after cli_args are processed (parsed, validated, and any
# normalization performed on them).  No other code should call it
def _init_global_context(cli_args):
    """Initialize the global context objects"""
    global CLIARGS
    CLIARGS = GlobalCLIArgs.from_options(cli_args)