2013-11-21 04:07:33 +00:00
|
|
|
.. _salt-mine:
|
|
|
|
|
2014-04-30 01:59:37 +00:00
|
|
|
.. index:: ! Mine, Salt Mine
|
|
|
|
|
2013-04-22 06:07:23 +00:00
|
|
|
=============
|
|
|
|
The Salt Mine
|
|
|
|
=============
|
|
|
|
|
2014-04-30 15:58:38 +00:00
|
|
|
The Salt Mine is used to collect arbitrary data from minions and store it on
|
|
|
|
the master. This data is then made available to all minions via the
|
|
|
|
:py:mod:`salt.modules.mine` module.
|
2013-04-22 06:07:23 +00:00
|
|
|
|
|
|
|
The data is gathered on the minion and sent back to the master where only
|
|
|
|
the most recent data is maintained (if long term data is required use
|
|
|
|
returners or the external job cache).
|
|
|
|
|
|
|
|
Mine Functions
|
|
|
|
==============
|
|
|
|
|
|
|
|
To enable the Salt Mine the `mine_functions` option needs to be applied to a
|
|
|
|
minion. This option can be applied via the minion's configuration file, or the
|
2014-04-30 15:58:38 +00:00
|
|
|
minion's Pillar. The `mine_functions` option dictates what functions are being
|
2014-04-30 19:04:59 +00:00
|
|
|
executed and allows for arguments to be passed in. If no arguments are passed,
|
|
|
|
an empty list must be added:
|
2013-04-22 06:07:23 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
mine_functions:
|
|
|
|
test.ping: []
|
2014-05-01 18:47:56 +00:00
|
|
|
network.ip_addrs:
|
2014-04-30 19:04:59 +00:00
|
|
|
interface: eth0
|
|
|
|
cidr: '10.0.0.0/8'
|
2013-04-22 06:07:23 +00:00
|
|
|
|
2014-08-09 17:13:59 +00:00
|
|
|
Mine Functions Aliases
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
Function aliases can be used to provide usage intentions or to allow multiple
|
|
|
|
calls of the same function with different arguments.
|
|
|
|
|
|
|
|
.. versionadded:: 2014.7
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
mine_functions:
|
|
|
|
network.ip_addrs: [eth0]
|
|
|
|
networkplus.internal_ip_addrs: []
|
|
|
|
internal_ip_addrs:
|
|
|
|
mine_function: network.ip_addrs
|
|
|
|
cidr: 192.168.0.0/16
|
|
|
|
loopback_ip_addrs:
|
2014-11-14 20:21:35 +00:00
|
|
|
mine_function: network.ip_addrs
|
|
|
|
lo: True
|
2014-08-09 17:13:59 +00:00
|
|
|
|
2013-04-22 06:07:23 +00:00
|
|
|
Mine Interval
|
|
|
|
=============
|
|
|
|
|
|
|
|
The Salt Mine functions are executed when the minion starts and at a given
|
|
|
|
interval by the scheduler. The default interval is every 60 minutes and can
|
|
|
|
be adjusted for the minion via the `mine_interval` option:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
mine_interval: 60
|
2014-04-30 15:55:57 +00:00
|
|
|
|
2014-12-23 19:14:31 +00:00
|
|
|
Mine in Salt-SSH
|
|
|
|
================
|
|
|
|
|
2015-03-05 22:02:01 +00:00
|
|
|
As of the 2015.2.0 release of salt, salt-ssh supports ``mine.get``.
|
2014-12-23 19:14:31 +00:00
|
|
|
|
|
|
|
Because the minions cannot provide their own ``mine_functions`` configuration,
|
|
|
|
we retrieve the args for specified mine functions in one of three places,
|
|
|
|
searched in the following order:
|
|
|
|
|
|
|
|
1. Roster data
|
|
|
|
2. Pillar
|
|
|
|
3. Master config
|
|
|
|
|
|
|
|
The ``mine_functions`` are formatted exactly the same as in normal salt, just
|
|
|
|
stored in a different location. Here is an example of a flat roster containing
|
|
|
|
``mine_functions``:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
test:
|
|
|
|
host: 104.237.131.248
|
|
|
|
user: root
|
|
|
|
mine_functions:
|
|
|
|
cmd.run: ['echo "hello!"']
|
|
|
|
network.ip_addrs:
|
|
|
|
interface: eth0
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Because of the differences in the architecture of salt-ssh, ``mine.get``
|
|
|
|
calls are somewhat inefficient. Salt must make a new salt-ssh call to each
|
|
|
|
of the minions in question to retrieve the requested data, much like a
|
|
|
|
publish call. However, unlike publish, it must run the requested function
|
|
|
|
as a wrapper function, so we can retrieve the function args from the pillar
|
|
|
|
of the minion in question. This results in a non-trivial delay in
|
|
|
|
retrieving the requested data.
|
|
|
|
|
2014-04-30 15:55:57 +00:00
|
|
|
Example
|
|
|
|
=======
|
|
|
|
|
|
|
|
One way to use data from Salt Mine is in a State. The values can be retrieved
|
|
|
|
via Jinja and used in the SLS file. The following example is a partial HAProxy
|
|
|
|
configuration file and pulls IP addresses from all minions with the "web" grain
|
|
|
|
to add them to the pool of load balanced servers.
|
|
|
|
|
|
|
|
:file:`/srv/pillar/top.sls`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
base:
|
|
|
|
'G@roles:web':
|
|
|
|
- web
|
|
|
|
|
|
|
|
:file:`/srv/pillar/web.sls`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
mine_functions:
|
|
|
|
network.ip_addrs: [eth0]
|
|
|
|
|
2014-05-16 22:22:38 +00:00
|
|
|
:file:`/etc/salt/minion.d/mine.conf`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2014-04-30 15:55:57 +00:00
|
|
|
mine_interval: 5
|
|
|
|
|
|
|
|
:file:`/srv/salt/haproxy.sls`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
haproxy_config:
|
2014-12-13 06:29:48 +00:00
|
|
|
file.managed:
|
2014-04-30 15:55:57 +00:00
|
|
|
- name: /etc/haproxy/config
|
|
|
|
- source: salt://haproxy_config
|
|
|
|
- template: jinja
|
|
|
|
|
|
|
|
:file:`/srv/salt/haproxy_config`:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
<...file contents snipped...>
|
|
|
|
|
|
|
|
{% for server, addrs in salt['mine.get']('roles:web', 'network.ip_addrs', expr_form='grain').items() %}
|
|
|
|
server {{ server }} {{ addrs[0] }}:80 check
|
|
|
|
{% endfor %}
|
|
|
|
|
2014-12-23 19:14:31 +00:00
|
|
|
<...file contents snipped...>
|