salt.modules.state

Control the state system on the minion.

State Caching

When a highstate is called, the minion automatically caches a copy of the last high data. If you then run a highstate with cache=True it will use that cached highdata and won't hit the fileserver except for salt:// links in the states themselves.

salt.modules.state.apply(mods=None, **kwargs)

2015.5.0 新版功能.

Apply states! This function will call highstate or state.sls based on the arguments passed in, state.apply is intended to be the main gateway for all state executions.

CLI 范例:

salt '*' state.apply
salt '*' state.apply test
salt '*' state.apply test,pkgs
salt.modules.state.check_request(name=None)

2015.5.0 新版功能.

Return the state request information, if any

CLI 范例:

salt '*' state.check_request
salt.modules.state.clear_cache()

Clear out cached state files, forcing even cache runs to refresh the cache on the next state execution.

Remember that the state cache is completely disabled by default, this execution only applies if cache=True is used in states

CLI 范例:

salt '*' state.clear_cache
salt.modules.state.clear_request(name=None)

2015.5.0 新版功能.

Clear out the state execution request without executing it

CLI 范例:

salt '*' state.clear_request
salt.modules.state.disable(states)

Disable state runs.

CLI 范例:

salt '*' state.disable highstate

salt '*' state.disable highstate,test.succeed_without_changes

注解

To disable a state file from running provide the same name that would be passed in a state.sls call.

salt '*' state.disable bind.config

salt.modules.state.enable(states)

Enable state function or sls run

CLI 范例:

salt '*' state.enable highstate

salt '*' state.enable test.succeed_without_changes

注解

To enable a state file from running provide the same name that would be passed in a state.sls call.

salt '*' state.disable bind.config

salt.modules.state.event(tagmatch='*', count=-1, quiet=False, sock_dir=None, pretty=False, node='minion')

Watch Salt's event bus and block until the given tag is matched

2016.3.0 新版功能.

This is useful for utilizing Salt's event bus from shell scripts or for taking simple actions directly from the CLI.

Enable debug logging to see ignored events.

参数:
  • tagmatch -- the event is written to stdout for each tag that matches this pattern; uses the same matching semantics as Salt's Reactor.
  • count -- this number is decremented for each event that matches the tagmatch parameter; pass -1 to listen forever.
  • quiet -- do not print to stdout; just block
  • sock_dir -- path to the Salt master's event socket file.
  • pretty -- Output the JSON all on a single line if False (useful for shell tools); pretty-print the JSON output if True.
  • node -- Watch the minion-side or master-side event bus.

CLI 范例:

salt-call --local state.event pretty=True
salt.modules.state.high(data, test=False, queue=False, **kwargs)

Execute the compound calls stored in a single set of high data This function is mostly intended for testing the state system

CLI 范例:

salt '*' state.high '{"vim": {"pkg": ["installed"]}}'
salt.modules.state.highstate(test=None, queue=False, **kwargs)

Retrieve the state data from the salt master for this minion and execute it

test

Notify states to execute in test-only (dry-run) mode.

Sets the test variable in the minion opts for the duration of the state run.

pillar

Additional pillar data to use for this function. Any pillar keys specified here will overwrite matching keys in the Pillar data.

在 2016.3.0 版更改: GPG-encrypted CLI Pillar data is now supported via the GPG renderer. See here for details.

pillar_enc

Specify which renderer to use to decrypt encrypted data located within the pillar value. Currently, only gpg is supported.

2016.3.0 新版功能.

queue : False

Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished.

This option starts a new thread for each queued state run so use this option sparingly.

localconfig
Instead of using running minion opts, load localconfig and merge that with the running minion opts. This functionality is intended for using "roots" of salt directories (with their own minion config, pillars, file_roots) to run highstate out of.
mock:

The mock option allows for the state run to execute without actually calling any states. This then returns a mocked return which will show the requisite ordering as well as fully validate the state run.

2015.8.4 新版功能.

CLI 范例:

salt '*' state.highstate

salt '*' state.highstate whitelist=sls1_to_run,sls2_to_run
salt '*' state.highstate exclude=sls_to_exclude
salt '*' state.highstate exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

salt '*' state.highstate pillar="{foo: 'Foo!', bar: 'Bar!'}"
salt.modules.state.list_disabled()

List the states which are currently disabled

CLI 范例:

salt '*' state.list_disabled
salt.modules.state.low(data, queue=False, **kwargs)

Execute a single low data call This function is mostly intended for testing the state system

CLI 范例:

salt '*' state.low '{"state": "pkg", "fun": "installed", "name": "vi"}'
salt.modules.state.pkg(pkg_path, pkg_sum, hash_type, test=False, **kwargs)

Execute a packaged state run, the packaged state run will exist in a tarball available locally. This packaged state can be generated using salt-ssh.

CLI 范例:

salt '*' state.pkg /tmp/state_pkg.tgz
salt.modules.state.request(mods=None, **kwargs)

2015.5.0 新版功能.

Request that the local admin execute a state run via salt-call state.run_request All arguments match state.apply

CLI 范例:

salt '*' state.request
salt '*' state.request test
salt '*' state.request test,pkgs
salt.modules.state.run_request(name='default', **kwargs)

2015.5.0 新版功能.

Execute the pending state request

CLI 范例:

salt '*' state.run_request
salt.modules.state.running(concurrent=False)

Return a list of strings that contain state return data if a state function is already running. This function is used to prevent multiple state calls from being run at the same time.

CLI 范例:

salt '*' state.running
salt.modules.state.show_highstate(queue=False, **kwargs)

Retrieve the highstate data from the salt master and display it

Custom Pillar data can be passed with the pillar kwarg.

CLI 范例:

salt '*' state.show_highstate
salt.modules.state.show_low_sls(mods, saltenv='base', test=None, queue=False, **kwargs)

Display the low data from a specific sls. The default environment is base, use saltenv to specify a different environment.

CLI 范例:

salt '*' state.show_low_sls foo
salt.modules.state.show_lowstate(queue=False, **kwargs)

List out the low data that will be applied to this minion

CLI 范例:

salt '*' state.show_lowstate
salt.modules.state.show_sls(mods, saltenv='base', test=None, queue=False, **kwargs)

Display the state data from a specific sls or list of sls files on the master. The default environment is base, use saltenv to specify a different environment.

This function does not support topfiles. For top.sls please use show_top instead.

Custom Pillar data can be passed with the pillar kwarg.

CLI 范例:

salt '*' state.show_sls core,edit.vim dev
salt.modules.state.show_top(queue=False, **kwargs)

Return the top data that the minion will use for a highstate

CLI 范例:

salt '*' state.show_top
salt.modules.state.single(fun, name, test=None, queue=False, **kwargs)

Execute a single state function with the named kwargs, returns False if insufficient data is sent to the command

By default, the values of the kwargs will be parsed as YAML. So, you can specify lists values, or lists of single entry key-value maps, as you would in a YAML salt file. Alternatively, JSON format of keyword values is also supported.

CLI 范例:

salt '*' state.single pkg.installed name=vim
salt.modules.state.sls(mods, saltenv=None, test=None, exclude=None, queue=False, pillarenv=None, **kwargs)

Execute a set list of state files from an environment.

test

Notify states to execute in test-only (dry-run) mode.

Sets the test variable in the minion opts for the duration of the state run.

pillar

Additional pillar data to use for this function. Any pillar keys specified here will overwrite matching keys in the Pillar data.

在 2016.3.0 版更改: GPG-encrypted CLI Pillar data is now supported via the GPG renderer. See here for details.

pillar_enc

Specify which renderer to use to decrypt encrypted data located within the pillar value. Currently, only gpg is supported.

2016.3.0 新版功能.

queue : False

Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished.

This option starts a new thread for each queued state run so use this option sparingly.

saltenv : None

Specify a file_roots environment.

在 0.17.0 版更改: Argument name changed from env to saltenv.

在 2014.7 版更改: Defaults to None. If no saltenv is specified, the minion config will be checked for a saltenv and if found, it will be used. If none is found, base will be used.

pillarenv : None
Specify a pillar_roots environment. By default all pillar environments merged together will be used.
concurrent:
WARNING: This flag is potentially dangerous. It is designed for use when multiple state runs can safely be run at the same Do not use this flag for performance optimization.
localconfig:
Instead of using running minion opts, load localconfig and merge that with the running minion opts. This functionality is intended for using "roots" of salt directories (with their own minion config, pillars, file_roots) to run highstate out of.
mock:

The mock option allows for the state run to execute without actually calling any states. This then returns a mocked return which will show the requisite ordering as well as fully validate the state run.

2015.8.4 新版功能.

CLI 范例:

salt '*' state.sls core,edit.vim dev
salt '*' state.sls core exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"

salt '*' state.sls myslsfile pillar="{foo: 'Foo!', bar: 'Bar!'}"
salt.modules.state.sls_id(id_, mods, saltenv='base', test=None, queue=False, **kwargs)

Call a single ID from the named module(s) and handle all requisites

2014.7.0 新版功能.

CLI 范例:

salt '*' state.sls_id apache http
salt.modules.state.template(tem, queue=False, **kwargs)

Execute the information stored in a template file on the minion.

This function does not ask a master for a SLS file to render but instead directly processes the file at the provided path on the minion.

CLI 范例:

salt '*' state.template '<Path to template on the minion>'
salt.modules.state.template_str(tem, queue=False, **kwargs)

Execute the information stored in a string from an sls template

CLI 范例:

salt '*' state.template_str '<Template String>'
salt.modules.state.top(topfn, test=None, queue=False, saltenv=None, **kwargs)

Execute a specific top file instead of the default. This is useful to apply configurations from a different environment (for example, dev or prod), without modifying the default top file.

CLI 范例:

salt '*' state.top reverse_top.sls
salt '*' state.top prod_top.sls exclude=sls_to_exclude
salt '*' state.top dev_top.sls exclude="[{'id': 'id_to_exclude'}, {'sls': 'sls_to_exclude'}]"