I want to select data from a database table (here mysql) with saltstack. In my test scenario I have a linux host called salt-master. On this host the database, the master and the minion are running.
My target is to select the data with the minion, but this does not work in my environment.
1) You see the data in the table. The data itself are of no relevance for the scenario.
MariaDB [salt]> SELECT minion_id,qmgr,object_type,value from mqobjects;
+--------------+-------+-------------+-------+
| minion_id | qmgr | object_type | value |
+--------------+-------+-------------+-------+
| salt-minion2 | QM200 | port | 14200 |
| salt-minion2 | QM201 | port | 14201 |
| salt-minion2 | QM201 | port | 15201 |
| salt-minion2 | QM201 | qlocal | QL1 |
| salt-minion2 | QM201 | qlocal | QL2 |
| salt-minion3 | QM301 | port | 14300 |
| salt-minion3 | QM301 | port | 14301 |
| salt-minion3 | QM302 | port | 14302 |
+--------------+-------+-------------+-------+
8 rows in set (0.00 sec)
2) Using the execution module mysql with the runner gives me the results I want to have.
salt-master:/srv/salt # salt-run salt.cmd mysql.query salt "SELECT minion_id,qmgr,object_type,value from mqobjects"
columns:
- minion_id
- qmgr
- object_type
- value
query time:
----------
human:
0.4ms
raw:
0.00037
results:
|_
- salt-minion2
- QM200
- port
- 14200
|_
- salt-minion2
- QM201
- port
- 14201
|_
- salt-minion2
- QM201
- port
- 15201
|_
- salt-minion2
- QM201
- qlocal
- QL1
|_
- salt-minion2
- QM201
- qlocal
- QL2
|_
- salt-minion3
- QM301
- port
- 14300
|_
- salt-minion3
- QM301
- port
- 14301
|_
- salt-minion3
- QM302
- port
- 14302
rows returned:
8
salt-master:/srv/salt #
3) Doing the same with the minion does not cause an error, but does not give any result either. Why?
salt-master:/srv/salt # salt salt-master mysql.query salt "SELECT minion_id,qmgr,object_type,value from mqobjects"
salt-master:
----------
salt-master:/srv/salt #
4) I also tried it with a sls file.
a) With check if db exists
salt-master:/srv/salt # cat cmdb/MqObjects2Grains.sls
queryMqObjects:
mysql_query.run:
- name: salt
- database: mysql
- query: "SELECT minion_id,qmgr,object_type,value from mqobjects"
- check_db_exists: True
salt-master:/srv/salt # salt salt-master state.apply cmdb.MqObjects2Grains
salt-master:
----------
ID: queryMqObjects
Function: mysql_query.run
Name: salt
Result: None
Comment: Database salt is not present
Started: 10:32:33.146025
Duration: 31.427 ms
Changes:
Summary for salt-master
------------
Succeeded: 1 (unchanged=1)
Failed: 0
------------
Total states run: 1
Total run time: 31.427 ms
salt-master:/srv/salt #
b) Without check if db exists
salt-master:/srv/salt # cat cmdb/MqObjects2Grains.sls
queryMqObjects:
mysql_query.run:
- name: salt
- database: mysql
- query: "SELECT minion_id,qmgr,object_type,value from mqobjects"
- check_db_exists: False
salt-master:/srv/salt # salt salt-master state.apply cmdb.MqObjects2Grains
salt-master:
----------
ID: queryMqObjects
Function: mysql_query.run
Name: salt
Result: True
Comment: {}
Started: 10:39:18.539604
Duration: 11.422 ms
Changes:
----------
query:
Executed
Summary for salt-master
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 11.422 ms
salt-master:/srv/salt #
Can anybody give me some hints, what I am doing wrong? That would be great!