salt.returners.postgres

Return data to a postgresql server

Note

There are three PostgreSQL returners. Any can function as an external master job cache. but each has different features. SaltStack recommends returners.pgjsonb if you are working with a version of PostgreSQL that has the appropriate native binary JSON types. Otherwise, review returners.postgres and returners.postgres_local_cache to see which module best suits your particular needs.

maintainer

None

maturity

New

depends

psycopg2

platform

all

To enable this returner the minion will need the psycopg2 installed and the following values configured in the minion or master config:

returner.postgres.host: 'salt'
returner.postgres.user: 'salt'
returner.postgres.passwd: 'salt'
returner.postgres.db: 'salt'
returner.postgres.port: 5432

Alternative configuration values can be used by prefacing the configuration. Any values not found in the alternative configuration will be pulled from the default location:

alternative.returner.postgres.host: 'salt'
alternative.returner.postgres.user: 'salt'
alternative.returner.postgres.passwd: 'salt'
alternative.returner.postgres.db: 'salt'
alternative.returner.postgres.port: 5432

Running the following commands as the postgres user should create the database correctly:

psql << EOF
CREATE ROLE salt WITH PASSWORD 'salt';
CREATE DATABASE salt WITH OWNER salt;
EOF

psql -h localhost -U salt << EOF
--
-- Table structure for table 'jids'
--

DROP TABLE IF EXISTS jids;
CREATE TABLE jids (
  jid   varchar(20) PRIMARY KEY,
  load  text NOT NULL
);

--
-- Table structure for table 'salt_returns'
--

DROP TABLE IF EXISTS salt_returns;
CREATE TABLE salt_returns (
  fun       varchar(50) NOT NULL,
  jid       varchar(255) NOT NULL,
  return    text NOT NULL,
  full_ret  text,
  id        varchar(255) NOT NULL,
  success   varchar(10) NOT NULL,
  alter_time   TIMESTAMP WITH TIME ZONE DEFAULT now()
);

CREATE INDEX idx_salt_returns_id ON salt_returns (id);
CREATE INDEX idx_salt_returns_jid ON salt_returns (jid);
CREATE INDEX idx_salt_returns_fun ON salt_returns (fun);
CREATE INDEX idx_salt_returns_updated ON salt_returns (alter_time);

--
-- Table structure for table `salt_events`
--

DROP TABLE IF EXISTS salt_events;
DROP SEQUENCE IF EXISTS seq_salt_events_id;
CREATE SEQUENCE seq_salt_events_id;
CREATE TABLE salt_events (
    id BIGINT NOT NULL UNIQUE DEFAULT nextval('seq_salt_events_id'),
    tag varchar(255) NOT NULL,
    data text NOT NULL,
    alter_time TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    master_id varchar(255) NOT NULL
);

CREATE INDEX idx_salt_events_tag on salt_events (tag);

EOF

Required python modules: psycopg2

To use the postgres returner, append '--return postgres' to the salt command.

salt '*' test.ping --return postgres

To use the alternative configuration, append '--return_config alternative' to the salt command.

New in version 2015.5.0.

salt '*' test.ping --return postgres --return_config alternative

To override individual configuration items, append --return_kwargs '{"key:": "value"}' to the salt command.

New in version 2016.3.0.

salt '*' test.ping --return postgres --return_kwargs '{"db": "another-salt"}'

salt.returners.postgres.event_return(events)

Return event to Pg server

Requires that configuration be enabled via 'event_return' option in master config.

salt.returners.postgres.get_fun(fun)

Return a dict of the last function called for all minions

salt.returners.postgres.get_jid(jid)

Return the information returned when the specified job id was executed

salt.returners.postgres.get_jids()

Return a list of all job ids

salt.returners.postgres.get_load(jid)

Return the load data that marks a specified jid

salt.returners.postgres.get_minions()

Return a list of minions

salt.returners.postgres.prep_jid(nocache=False, passed_jid=None)

Do any work necessary to prepare a JID, including sending a custom id

salt.returners.postgres.returner(ret)

Return data to a postgres server

salt.returners.postgres.save_load(jid, load, minions=None)

Save the load to the specified jid id

© 2021 SaltStack.
Licensed under the Apache License, Version 2.0.
https://docs.saltproject.io/en/latest/ref/returners/all/salt.returners.postgres.html