def run(self): super(GrapherCLI, self).run() loader, inventory, variable_manager = CLI._play_prereqs() # Looks like the display is a singleton. This instruction will NOT return a new instance. # This is why we set the verbosity later because someone set it before us. display = Display() display.verbosity = self.options.verbosity grapher = PlaybookGrapher( data_loader=loader, inventory_manager=inventory, variable_manager=variable_manager, display=display, tags=self.options.tags, skip_tags=self.options.skip_tags, playbook_filename=self.options.playbook_filename, include_role_tasks=self.options.include_role_tasks) grapher.make_graph() svg_path = grapher.render_graph(self.options.output_filename, self.options.save_dot_file) post_processor = PostProcessor(svg_path=svg_path) post_processor.post_process( graph_representation=grapher.graph_representation) post_processor.write() display.display(f"fThe graph has been exported to {svg_path}") return svg_path
def __init__(self, tags: List[str] = None, skip_tags: List[str] = None): """ :param tags: Only add plays and tasks tagged with these values :param skip_tags: Only add plays and tasks whose tags do not match these values """ loader, inventory, variable_manager = CLI._play_prereqs() self.data_loader = loader self.inventory_manager = inventory self.variable_manager = variable_manager self.tags = tags or ["all"] self.skip_tags = skip_tags or []
"diff": False, "inventory": ["./hosts"], "listhosts": None, "subset": "server_a", "extra_vars": ["targetHost=server_b", "sourseHost=server_a"], "ask_vault_pass": False, "vault_password_files": [], "vault_ids": [], "forks": 5, "module_path": None, "listtasks": None, "listtags": None, "step": None, "start_at_task": None, }) context._init_global_context(options) loader, inventory, variable_manager = CLI._play_prereqs() CLI.get_host_list(inventory, context.CLIARGS["subset"]) pbex = PlaybookExecutor(playbooks=["./playbooks/roles/common/tasks/main.yml"], inventory=inventory, variable_manager=variable_manager, loader=loader, passwords=dict(conn_pass="******", become_pass="******")) result_callback = ResultCallback() pbex._tqm._stdout_callback = result_callback result_id = pbex.run() result = result_callback.getResult()
def __init__(self, agent_address, group_name='agent', username=None, password=None): self.inventory_filename = None with tempfile.NamedTemporaryFile('w', delete=False) as inventory: print('[{}]'.format(group_name), file=inventory) print(agent_address, file=inventory) self.inventory_filename = inventory.name self.passwords = { 'conn_pass': password, 'become_pass': password, } self.options = Options( # Fill in required default values ask_pass=False, ask_su_pass=False, ask_sudo_pass=False, ask_vault_pass=False, become=False, become_ask_pass=False, become_method='sudo', become_user='******', check=False, connection='smart', diff=False, extra_vars=[], flush_cache=None, force_handlers=False, forks=5, inventory=[self.inventory_filename], listhosts=None, listtags=None, listtasks=None, module_path=None, new_vault_id=None, new_vault_password_files=[], private_key_file=None, remote_user='', scp_extra_args='', sftp_extra_args='', skip_tags=['questions'], ssh_common_args='', ssh_extra_args='', start_at_task=None, step=None, su=False, su_user=None, subset=None, sudo=False, sudo_user=None, syntax=None, tags=['all'], timeout=10, vault_ids=[], vault_password_files=[], verbosity=0, ) if username is None: self.options.remote_user = '******' self.options.private_key_file = '/home/openbach/.ssh/id_rsa' else: self.options.remote_user = username if context is None: self.loader, self.inventory, self.variables = CLI._play_prereqs( self.options) else: context._init_global_context(self.options) self.loader, self.inventory, self.variables = CLI._play_prereqs()