Saltstack module config 详解

config.items

Return the complete config from the currently running minion process.
This includes defaults for values not set in the config file.

CLI Example:

    salt '*' config.items

config.dot_vals

Pass in a configuration value that should be preceded by the module name
and a dot, this will return a list of all read key/value pairs

CLI Example:

    salt '*' config.dot_vals host

config.backup_mode

Return the backup mode

CLI Example:

    salt '*' config.backup_mode

config.get

.. versionadded: 0.14.0

Attempt to retrieve the named value from the minion config file, pillar,
grains or the master config. If the named value is not available, return
the value specified by the ``default`` argument. If this argument is not
specified, ``default`` falls back to an empty string.

Values can also be retrieved from nested dictionaries. Assume the below
data structure:

    {'pkg': {'apache': 'httpd'}}

To retrieve the value associated with the ``apache`` key, in the
sub-dictionary corresponding to the ``pkg`` key, the following command can
be used:

    salt myminion config.get pkg:apache

The ``:`` (colon) is used to represent a nested dictionary level.

Changed in version 2015.5.0
    The ``delimiter`` argument was added, to allow delimiters other than
    ``:`` to be used.

This function traverses these data stores in this order, returning the
first match found:

- Minion configuration
- Minion's grains
- Minion's pillar data
- Master configuration (requires :conf_minion:`pillar_opts` to be set to
  ``True`` in Minion config file in order to work)

This means that if there is a value that is going to be the same for the
majority of minions, it can be configured in the Master config file, and
then overridden using the grains, pillar, or Minion config file.

Adding config options to the Master or Minion configuration file is easy:

    my-config-option: value
    cafe-menu:
      - egg and bacon
      - egg sausage and bacon
      - egg and spam
      - egg bacon and spam
      - egg bacon sausage and spam
      - spam bacon sausage and spam
      - spam egg spam spam bacon and spam
      - spam sausage spam spam bacon spam tomato and spam

Note:
    Minion configuration options built into Salt (like those defined
    :ref:`here <configuration-salt-minion>`) will *always* be defined in
    the Minion configuration and thus *cannot be overridden by grains or
    pillar data*. However, additional (user-defined) configuration options
    (as in the above example) will not be in the Minion configuration by
    default and thus can be overridden using grains/pillar data by leaving
    the option out of the minion config file.

**Arguments**

delimiter
    New in version 2015.5.0

    Override the delimiter used to separate nested levels of a data
    structure.

merge
    New in version 2015.5.0

    If passed, this parameter will change the behavior of the function so
    that, instead of traversing each data store above in order and
    returning the first match, the data stores are first merged together
    and then searched. The pillar data is merged into the master config
    data, then the grains are merged, followed by the Minion config data.
    The resulting data structure is then searched for a match. This allows
    for configurations to be more flexible.

    Note:

        The merging described above does not mean that grain data will end
        up in the Minion's pillar data, or pillar data will end up in the
        master config data, etc. The data is just combined for the purposes
        of searching an amalgam of the different data stores.

    The supported merge strategies are as follows:

    - **recurse** - If a key exists in both dictionaries, and the new value
      is not a dictionary, it is replaced. Otherwise, the sub-dictionaries
      are merged together into a single dictionary, recursively on down,
      following the same criteria. For example:

          >>> dict1 = {'foo': {'bar': 1, 'qux': True},
                       'hosts': ['a', 'b', 'c'],
                       'only_x': None}
          >>> dict2 = {'foo': {'baz': 2, 'qux': False},
                       'hosts': ['d', 'e', 'f'],
                       'only_y': None}
          >>> merged
          {'foo': {'bar': 1, 'baz': 2, 'qux': False},
           'hosts': ['d', 'e', 'f'],
           'only_dict1': None,
           'only_dict2': None}

    - **overwrite** - If a key exists in the top level of both
      dictionaries, the new value completely overwrites the old. For
      example:

          >>> dict1 = {'foo': {'bar': 1, 'qux': True},
                       'hosts': ['a', 'b', 'c'],
                       'only_x': None}
          >>> dict2 = {'foo': {'baz': 2, 'qux': False},
                       'hosts': ['d', 'e', 'f'],
                       'only_y': None}
          >>> merged
          {'foo': {'baz': 2, 'qux': False},
           'hosts': ['d', 'e', 'f'],
           'only_dict1': None,
           'only_dict2': None}

CLI Example:

    salt '*' config.get pkg:apache
    salt '*' config.get lxc.container_profile:centos merge=recurse

config.valid_fileproto

Returns a boolean value based on whether or not the URI passed has a valid
remote file protocol designation

CLI Example:

    salt '*' config.valid_fileproto salt://path/to/file

config.gather_bootstrap_script

Download the salt-bootstrap script, and return its location

bootstrap
    URL of alternate bootstrap script

CLI Example:

    salt '*' config.gather_bootstrap_script

config.option

Returns the setting for the specified config value. The priority for
matches is the same as in :py:func:`config.get <salt.modules.config.get>`,
only this function does not recurse into nested data structures. Another
difference between this function and :py:func:`config.get
<salt.modules.config.get>` is that it comes with a set of "sane defaults".
To view these, you can run the following command:

    salt '*' config.option '*' omit_all=True wildcard=True

default
    The default value if no match is found. If not specified, then the
    fallback default will be an empty string, unless ``wildcard=True``, in
    which case the return will be an empty dictionary.

omit_opts : False
    Pass as ``True`` to exclude matches from the minion configuration file

omit_grains : False
    Pass as ``True`` to exclude matches from the grains

omit_pillar : False
    Pass as ``True`` to exclude matches from the pillar data

omit_master : False
    Pass as ``True`` to exclude matches from the master configuration file

omit_all : True
    Shorthand to omit all of the above and return matches only from the
    "sane defaults".

    New in version 3000

wildcard : False
    If used, this will perform pattern matching on keys. Note that this
    will also significantly change the return data. Instead of only a value
    being returned, a dictionary mapping the matched keys to their values
    is returned. For example, using ``wildcard=True`` with a ``key`` of
    ``'foo.ba*`` could return a dictionary like so:

        {'foo.bar': True, 'foo.baz': False}

    New in version 3000

CLI Example:

    salt '*' config.option redis.host

config.merge

Retrieves an option based on key, merging all matches.

Same as ``option()`` except that it merges all matches, rather than taking
the first match.

CLI Example:

    salt '*' config.merge schedule

config.manage_mode

Return a mode value, normalized to a string

CLI Example:

    salt '*' config.manage_mode
posted @ 2020-03-28 20:26  random_lee  阅读(185)  评论(0编辑  收藏  举报