How to use roles_path method in molecule

Best Python code snippet using molecule_python

_playbook.py

Source:_playbook.py Github

copy

Full Screen

...67 @property68 def playbook_dirname(self) -> str:69 return tobiko.check_valid_type(self._playbook_dirname, str)70 @property71 def roles_path(self) -> typing.List[str]:72 roles_path = self._roles_path73 if roles_path is None:74 if roles_path is None:75 roles_path = []76 else:77 roles_path = list(roles_path)78 playbook_dirname = self._playbook_dirname79 if playbook_dirname is not None:80 playbook_roles_dir = os.path.join(playbook_dirname, 'roles')81 roles_path = ([playbook_roles_dir] +82 roles_path +83 [playbook_dirname])84 self._roles_path = roles_path85 return list(roles_path)...

Full Screen

Full Screen

runner.py

Source:runner.py Github

copy

Full Screen

1#!/usr/bin/env python32import pathlib3import yaml4import docutils.parsers.rst5import docutils.core6from sphinx.errors import ExtensionError7from sphinx.util import logging8import ansible_runner9logger = logging.getLogger(__name__)10def write_play(play_content, tmp_dir):11 tmp_dir = pathlib.Path(tmp_dir)12 tmp_dir.mkdir(exist_ok=True)13 temp_file = tmp_dir / "temp_file.yaml"14 temp_file.write_text(play_content)15 return temp_file16def run_playbook(play_file, roles_path=None):17 logger.info("[ansible_runner] Running: {}".format(play_file))18 r = ansible_runner.run(19 private_data_dir=str(play_file.parent),20 playbook=play_file.name,21 roles_path=roles_path,22 )23 return r24def get_outputs(play_file, roles_path=None):25 r = run_playbook(play_file, roles_path=roles_path)26 if r.rc:27 raise ExtensionError("ansible execution has failed")28 outputs = {}29 for each_host_event in r.events:30 if each_host_event["event"] == "runner_on_ok":31 event_data = each_host_event["event_data"]32 task = each_host_event["event_data"].get("task")33 res = each_host_event["event_data"].get("res")34 if not (task and res):35 continue36 if task == "Gathering Facts":37 continue38 print(f"{task}> {res}")39 outputs[task] = res40 return outputs41def evaluate_playbook(play_content, roles_path=None, tmp_dir=None):42 play_file = write_play(play_content, tmp_dir=tmp_dir)43 outputs = get_outputs(play_file, roles_path=roles_path)44 return outputs45def evaluate_tasks(tasks, roles_path=None, tmp_dir=None):46 playbook_content = "- hosts: localhost\n tasks:\n"47 for block in tasks:48 task_str = yaml.dump([block["task"]])49 new_lines = [" " + l for l in task_str.split("\n")]50 playbook_content += "\n".join(new_lines) + "\n"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful