splunk / splunk-ansible

Ansible playbooks for configuring and managing Splunk Enterprise and Universal Forwarder deployments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Defaults cascading not possible anymore

SkyKnightSKS opened this issue · comments

The function below does not allow env ever to use headers, nor does it ever allow Host to be used.
As the host setting in the basedefaults is empty.

In the past it loaded the basedefaults, merged with the baked defaults, the result of this was then passed on to the next merge.

def loadDefaults():
    """
    Generate a consolidated map containing variables used to drive Ansible functionality.
    Defaults are loaded in a particular order such that latter overrides former.
    """
    # Load base defaults from splunk-ansible repository
    base = loadBaseDefaults()
    # Build an array of new defaults to override the base
    ymls = []
    config = base.get("config")
    if not config:
        return base
    # Add "baked" files to array
    ymls.extend(loadBakedDefaults(config))
    # Add "env" URLs to array
    ymls.extend(loadEnvDefaults(config))
    # Add "host" URLs to array
    ymls.extend(loadHostDefaults(config))
    # For each new YAML discovered, merge them with base in order so values get superseded
    for yml in ymls:
        base = mergeDefaults(base, yml["key"], yml["src"])
    return base

Currently the only method I see to use the HostDefaults, is to override the baseDefaults.

My suggestion would be to merge the bakedDefaults with the baseDefaults, and use this configuration for loading the Env and Host defaults.

def loadDefaults():
    """
    Generate a consolidated map containing variables used to drive Ansible functionality.
    Defaults are loaded in a particular order such that latter overrides former.
    """
    # Load base defaults from splunk-ansible repository
    base = loadBaseDefaults()
    # Build an array of new defaults to override the base
    ymls = []
    config = base.get("config")
    if not config:
        return base
    # Get baked sources
    ymlBaked = loadBakedDefaults(config)

    # Add additional config settings to the basedefaults to use down the line
    bakedbase = base
    for yml in ymlBaked:
        mergeDefaults(bakedbase, yml["key"], yml["src"])
    bakedconfig = bakedbase.get("config", None)

    # Add "baked" files to array
    ymls.extend(ymlBaked)
    if bakedconfig:
        # Add "env" URLs to array
        ymls.extend(loadEnvDefaults(bakedconfig))
        # Add "host" URLs to array
        ymls.extend(loadHostDefaults(bakedconfig))
    # For each new YAML discovered, merge them with base in order so values get superseded
    for yml in ymls:
        base = mergeDefaults(base, yml["key"], yml["src"])
    return base

I think I understand the pain point you're having, let me see if I can reproduce a test case and add that fix for you.