def execute_play(cls, play_name): """Execute a specific play Args: play_name(str): playbook name """ graph_ref = GraphReference() with graph_ref.get_session() as session: play_path = GraphReference.get_play_path(session) if not play_path: return file_filter = ( lambda f: os.path.isfile(os.path.join(play_path, f)) and os.path.splitext(f)[0] == play_name ) play_file = [f for f in os.listdir(play_path) if file_filter(f)][0] subprocess.Popen( os.path.join(play_path, play_file), stderr=subprocess.DEVNULL, close_fds=True, )
def plays(cls): """Get plays (user-defined scripts) available for execution Returns: tuple: list of bash files as well as python scripts """ graph_ref = GraphReference() with graph_ref.get_session() as session: play_path = GraphReference.get_play_path(session) if not play_path: return ([], []) play_files = [ f for f in os.listdir(play_path) if os.path.isfile(os.path.join(play_path, f)) ] is_py_file = lambda f: os.path.splitext(f)[1] == ".py" return ( [os.path.splitext(f)[0] for f in play_files if not is_py_file(f)], [os.path.splitext(f)[0] for f in play_files if is_py_file(f)], )