salt.modules.etcd_mod

Execution module to work with etcd

depends:
  • python-etcd

In order to use an etcd server, a profile should be created in the master configuration file:

my_etd_config:
  etcd.host: 127.0.0.1
  etcd.port: 4001

It is technically possible to configure etcd without using a profile, but this is not considered to be a best practice, especially when multiple etcd servers or clusters are available.

etcd.host: 127.0.0.1
etcd.port: 4001
salt.modules.etcd_mod.get(key, recurse=False, profile=None)

2014.7.0 新版功能.

Get a value from etcd, by direct path. Returns None on failure.

CLI范例:

salt myminion etcd.get /path/to/key
salt myminion etcd.get /path/to/key profile=my_etcd_config
salt myminion etcd.get /path/to/key recurse=True profile=my_etcd_config
salt.modules.etcd_mod.ls(path='/', profile=None)

2014.7.0 新版功能.

Return all keys and dirs inside a specific path. Returns an empty dict on failure.

命令行接口CLI 范例:

salt myminion etcd.ls /path/to/dir/
salt myminion etcd.ls /path/to/dir/ profile=my_etcd_config
salt.modules.etcd_mod.rm(key, recurse=False, profile=None)

2014.7.0 新版功能.

Delete a key from etcd. Returns True if the key was deleted, False if it wasn not and None if there was a failure.

命令行接口CLI 范例:

salt myminion etcd.rm /path/to/key
salt myminion etcd.rm /path/to/key profile=my_etcd_config
salt myminion etcd.rm /path/to/dir recurse=True profile=my_etcd_config
salt.modules.etcd_mod.set(key, value, profile=None, ttl=None, directory=False)

2014.7.0 新版功能.

Set a key in etcd by direct path. Optionally, create a directory or set a TTL on the key. Returns None on failure.

命令行接口CLI 范例:

salt myminion etcd.set /path/to/key value
salt myminion etcd.set /path/to/key value profile=my_etcd_config
salt myminion etcd.set /path/to/dir '' directory=True
salt myminion etcd.set /path/to/key value ttl=5
salt.modules.etcd_mod.tree(path='/', profile=None)

2014.7.0 新版功能.

Recurse through etcd and return all values. Returns None on failure.

命令行接口CLI 范例:

salt myminion etcd.tree
salt myminion etcd.tree profile=my_etcd_config
salt myminion etcd.tree /path/to/keys profile=my_etcd_config
salt.modules.etcd_mod.update(fields, path='', profile=None)

2016.3.0 新版功能.

Sets a dictionary of values in one call. Useful for large updates in syndic environments. The dictionary can contain a mix of formats such as:

{
  '/some/example/key': 'bar',
  '/another/example/key': 'baz'
}

Or it may be a straight dictionary, which will be flattened to look like the above format:

{
    'some': {
        'example': {
            'key': 'bar'
        }
    },
    'another': {
        'example': {
            'key': 'baz'
        }
    }
}

You can even mix the two formats and it will be flattened to the first format. Leading and trailing '/' will be removed.

Empty directories can be created by setting the value of the key to an empty dictionary.

The 'path' parameter will optionally set the root of the path to use.

命令行接口CLI 范例:

salt myminion etcd.update "{'/path/to/key': 'baz', '/another/key': 'bar'}"
salt myminion etcd.update "{'/path/to/key': 'baz', '/another/key': 'bar'}" profile=my_etcd_config
salt myminion etcd.update "{'/path/to/key': 'baz', '/another/key': 'bar'}" path='/some/root'
salt.modules.etcd_mod.watch(key, recurse=False, profile=None, timeout=0, index=None)

2016.3.0 新版功能.

Makes a best effort to watch for a key or tree change in etcd. Returns a dict containing the new key value ( or None if the key was deleted ), the modifiedIndex of the key, whether the key changed or not, the path to the key that changed and whether it is a directory or not.

If something catastrophic happens, returns {}

命令行接口CLI 范例:

salt myminion etcd.watch /path/to/key
salt myminion etcd.watch /path/to/key timeout=10
salt myminion etcd.watch /patch/to/key profile=my_etcd_config index=10