INNER CODE UNIT · Python

read_all_yml

timothystewart6/k3s-ansible · .github/scripts/test-default-interface.py:46

def read_all_yml(root):
    path = os.path.join(root, "inventory", "sample", "group_vars", "all.yml")
    with open(path, "r") as handle:
        return handle.read()


def extract_value(content, key):
    # Match a quoted value assigned to the key, e.g. flannel_iface: "...".
    match = re.search(r"^%s:\s*\"(.+)\"\s*$" % re.escape(key), content, re.M)
    if not match:
        fail("could not find %s in the sample inventory" % key)
    return match.group(1)


def resolve(env, expression, facts):
    template = env.from_string(expression)
    return template.render(ansible_facts=facts)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…