Skip to content

Instantly share code, notes, and snippets.

@FunTimeCoding
Last active February 19, 2016 14:41
Show Gist options
  • Save FunTimeCoding/86ae3181eb043bff388f to your computer and use it in GitHub Desktop.
Save FunTimeCoding/86ae3181eb043bff388f to your computer and use it in GitHub Desktop.
Use MySQL as an extended pillar in Salt.

Master config

file_roots:
  base:
    - /srv/salt/state

pillar_roots:
  base:
    - /srv/salt/pillar

mysql:
  user: salt
  pass: salt
  db: salt
  host: raven.ping.lan

ext_pillar:
  - mysql:
      fromdb:
        query: 'SELECT pillar, value FROM pillar WHERE minion_id = %s'
        depth: 2
        as_list: True

MySQL schema

CREATE TABLE pillar (
    pillar_id INTEGER NOT NULL,
    minion_id VARCHAR(30) NOT NULL,
    pillar VARCHAR(30) NOT NULL,
    value VARCHAR(30) NOT NULL,
    CONSTRAINT pk_pillar PRIMARY KEY (pillar_id)
);

MySQL output

mysql> select pillar, value from pillar where minion_id = 'nexus'\G
*************************** 1. row ***************************
pillar: foo
 value: bar
1 row in set (0.00 sec)

Salt commands to see ext_pillar information.

salt nexus saltutil.refresh_pillar
salt nexus pillar.data
@davidpsv17
Copy link

Hi, I'm trying to use Mysql module but doesn't works.
This is my master configuration:

mysql:
user: "root"
pass: "password"
db: "ADMIN_db"
host: localhost

ext_pillar:

  • mysql:
    fromdb:
    query: 'SELECT * FROM adminApp_m_service'
    depth: 2
    as_list: True

When I run salt nexus saltutil.refresh_pillar and salt nexus pillar.data, doesn't show anything.
If I run salt-run pillar.show_pillar the next error appears:
[CRITICAL] Specified ext_pillar interface mysql is unavailable

Can you help me please? Where I am wrong?

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment