Module Expr Str ImportFrom alias ImportFrom alias Import alias Import alias Import alias Import alias Import alias Import alias TryExcept body Import alias Import alias Assign NameStore NameLoad handlers ExceptHandler type NameLoad body Assign NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Str FunctionDef arguments args defaults body If UnaryOpNot NameLoad body Return NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults NameLoad body Expr Str Assign NameStore Dict Str Str Str Str Str Str Str Str Str Num Assign NameStore Dict Str Str Str Str Str Str Str Str Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr NameLoad NameLoad NameLoad keyword NameLoad keyword NameLoad keyword NameLoad If CompareIn Str NameLoad body Assign SubscriptStore NameLoad Index Str Call NameLoad SubscriptLoad NameLoad Index Str Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign NameStore Call NameLoad NameLoad TryExcept body Assign NameStore Dict If Call AttributeLoad NameLoad attr Str body Assign SubscriptStore NameLoad Index Str Call AttributeLoad NameLoad attr Str If Call AttributeLoad NameLoad attr Str body Assign SubscriptStore NameLoad Index Str Call AttributeLoad NameLoad attr Str If Call AttributeLoad NameLoad attr Str body Assign SubscriptStore NameLoad Index Str Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr keyword Call AttributeLoad NameLoad attr Str keyword Call AttributeLoad NameLoad attr Str keyword Call AttributeLoad NameLoad attr Str keyword Call AttributeLoad NameLoad attr Str keyword Call AttributeLoad NameLoad attr Str handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Raise Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr TryFinally body TryExcept body Expr Yield NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Assign NameStore AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Str Raise NameLoad orelse If NameLoad body Expr Call AttributeLoad NameLoad attr Str orelse Expr Call AttributeLoad NameLoad attr Str finalbody Expr Call AttributeLoad NameLoad attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str TryExcept body With Call NameLoad NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Call AttributeLoad AttributeLoad NameLoad attr attr SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Call AttributeLoad NameLoad attr Str NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Call AttributeLoad NameLoad attr Str Call AttributeLoad NameLoad attr handlers ExceptHandler type AttributeLoad AttributeLoad NameLoad attr attr body Expr Call AttributeLoad NameLoad attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str With Call NameLoad NameLoad keyword NameLoad NameStore body For NameStore NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad SubscriptLoad NameLoad Index Str Call AttributeLoad NameLoad attr Str Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str With Call NameLoad keyword NameLoad NameStore body Assign NameStore Str TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr body Pass decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Pass decorator_list FunctionDef arguments args NameParam defaults body Expr Str With Call NameLoad keyword NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr If NameLoad body Return SubscriptLoad NameLoad Index Num Return Dict decorator_list FunctionDef arguments args NameParam defaults body Expr Str With Call NameLoad keyword NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Dict If NameLoad body For TupleStore NameStore NameStore NameLoad body Assign SubscriptStore NameLoad Index NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str With Call NameLoad keyword NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Dict If NameLoad body For TupleStore NameStore NameStore NameStore NameLoad body Assign SubscriptStore NameLoad Index NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args defaults body Expr Str With Call NameLoad keyword NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Dict For TupleStore NameStore NameStore NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args defaults body Expr Str With Call NameLoad keyword NameLoad keyword NameLoad NameStore body Assign NameStore Str Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore ListLoad For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad NameLoad body Expr Str Return IfExp CompareIsNot NameLoad NameLoad NameLoad Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr decorator_list
N/A N/A 
Return data to a PostgreSQL server with json data stored in Pg's jsonb data type

:maintainer:    Dave Boucha <dave@saltstack.com>, Seth House <shouse@saltstack.com>, C. R. Oldham <cr@saltstack.com>
:maturity:      new
:depends:       python-psycopg2
:platform:      all

To enable this returner, the minion will need the python client for PostgreSQL
installed and the following values configured in the minion or master
config. These are the defaults:

.. code-block:: yaml

    returner.pgjsonb.host: 'salt'
    returner.pgjsonb.user: 'salt'
    returner.pgjsonb.pass: 'salt'
    returner.pgjsonb.db: 'salt'
    returner.pgjsonb.port: 5432

SSL is optional. The defaults are set to None. If you do not want to use SSL,
either exclude these options or set them to None.

.. code-block:: yaml

    returner.pgjsonb.ssl_ca: None
    returner.pgjsonb.ssl_cert: None
    returner.pgjsonb.ssl_key: None

Alternative configuration values can be used by prefacing the configuration
with `alternative.`. Any values not found in the alternative configuration will
be pulled from the default location. As stated above, SSL configuration is
optional. The following ssl options are simply for illustration purposes:

.. code-block:: yaml

    alternative.pgjsonb.host: 'salt'
    alternative.pgjsonb.user: 'salt'
    alternative.pgjsonb.pass: 'salt'
    alternative.pgjsonb.db: 'salt'
    alternative.pgjsonb.port: 5432
    alternative.pgjsonb.ssl_ca: '/etc/pki/mysql/certs/localhost.pem'
    alternative.pgjsonb.ssl_cert: '/etc/pki/mysql/certs/localhost.crt'
    alternative.pgjsonb.ssl_key: '/etc/pki/mysql/certs/localhost.key'

Use the following Pg database schema:

.. code-block:: sql

    CREATE DATABASE  salt
      WITH ENCODING 'utf-8';

    --
    -- Table structure for table `jids`
    --
    DROP TABLE IF EXISTS jids;
    CREATE TABLE jids (
       jid varchar(255) NOT NULL primary key,
       load jsonb NOT NULL
    );
    CREATE INDEX idx_jids_jsonb on jids
           USING gin (load)
           WITH (fastupdate=on);

    --
    -- 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 jsonb NOT NULL,
      id varchar(255) NOT NULL,
      success varchar(10) NOT NULL,
      full_ret jsonb 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_return ON salt_returns
        USING gin (return) with (fastupdate=on);
    CREATE INDEX idx_salt_returns_full_ret ON salt_returns
        USING gin (full_ret) with (fastupdate=on);

    --
    -- 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 jsonb 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);
    CREATE INDEX idx_salt_events_data ON salt_events
        USING gin (data) with (fastupdate=on);

Required python modules: Psycopg2

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

.. code-block:: bash

    salt '*' test.ping --return pgjsonb

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

.. versionadded:: 2015.5.0

.. code-block:: bash

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

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

.. versionadded:: 2016.3.0

.. code-block:: bash

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

 __future__ absolute_import contextlib contextmanager N/A sys N/A time N/A logging N/A salt.returners N/A salt.utils.jid N/A salt.exceptions N/A N/A N/A psycopg2 N/A psycopg2.extras N/A HAS_PG True N/A N/A N/A ImportError N/A N/A HAS_PG False N/A log N/A N/A logging getLogger __name__ N/A __virtualname__ pgjsonb __virtual__ N/A N/A N/A N/A N/A N/A HAS_PG N/A N/A False N/A True N/A _get_options N/A N/A ret N/A None N/A N/A 
    Returns options used for the MySQL connection.
     N/A defaults N/A host user pass db port localhost salt salt salt 5432 N/A attrs N/A host user pass db port host user pass db port N/A _options N/A N/A N/A salt returners get_returner_options N/A N/A returner.{0} format __virtualname__ ret attrs __salt__ __salt__ __opts__ __opts__ defaults defaults N/A N/A port _options N/A N/A N/A _options N/A port N/A int N/A _options N/A port N/A _options N/A _get_serv N/A N/A ret commit N/A None False N/A N/A 
    Return a Pg cursor
     N/A _options N/A _get_options ret N/A N/A N/A ssl_options N/A N/A N/A N/A _options get ssl_ca N/A N/A N/A ssl_options N/A ca N/A N/A _options get ssl_ca N/A N/A N/A _options get ssl_cert N/A N/A N/A ssl_options N/A cert N/A N/A _options get ssl_cert N/A N/A N/A _options get ssl_key N/A N/A N/A ssl_options N/A key N/A N/A _options get ssl_key N/A conn N/A N/A psycopg2 connect host N/A N/A _options get host user N/A N/A _options get user password N/A N/A _options get pass database N/A N/A _options get db port N/A N/A _options get port N/A N/A N/A N/A psycopg2 OperationalError N/A exc N/A N/A N/A N/A N/A salt exceptions SaltMasterError N/A N/A pgjsonb returner could not connect to database: {exc} format exc exc N/A cursor N/A N/A conn cursor N/A N/A N/A N/A N/A N/A cursor N/A N/A N/A N/A psycopg2 DatabaseError N/A err N/A N/A error N/A err args N/A N/A N/A N/A sys stderr write N/A str error N/A N/A N/A cursor execute ROLLBACK N/A err N/A N/A commit N/A N/A N/A N/A cursor execute COMMIT N/A N/A N/A N/A cursor execute ROLLBACK N/A N/A N/A N/A conn close N/A contextmanager returner N/A N/A ret N/A N/A N/A 
    Return data to a Pg server
     N/A N/A N/A N/A _get_serv ret commit True cur N/A N/A sql INSERT INTO salt_returns
                    (fun, jid, return, id, success, full_ret, alter_time)
                    VALUES (%s, %s, %s, %s, %s, %s, %s) N/A N/A N/A cur execute sql N/A N/A ret N/A fun N/A ret N/A jid N/A N/A N/A psycopg2 extras Json N/A ret N/A return N/A ret N/A id N/A N/A ret get success False N/A N/A N/A psycopg2 extras Json ret N/A N/A time strftime %Y-%m-%d %H:%M:%S %z N/A N/A time localtime N/A N/A N/A N/A N/A salt exceptions SaltMasterError N/A N/A N/A N/A log critical Could not store return with pgjsonb returner. PostgreSQL server unavailable. N/A event_return N/A N/A events N/A N/A N/A 
    Return event to Pg server

    Requires that configuration be enabled via 'event_return'
    option in master config.
     N/A N/A _get_serv events commit True cur N/A N/A event events N/A N/A tag N/A N/A event get tag N/A data N/A N/A event get data N/A sql INSERT INTO salt_events (tag, data, master_id, alter_time)
                     VALUES (%s, %s, %s, %s) N/A N/A N/A cur execute sql N/A tag N/A N/A N/A psycopg2 extras Json data N/A __opts__ N/A id N/A N/A time strftime %Y-%m-%d %H:%M:%S %z N/A N/A time localtime N/A save_load N/A N/A jid load N/A N/A N/A 
    Save the load to the specified jid id
     N/A N/A _get_serv commit True cur N/A N/A sql INSERT INTO jids
               (jid, load)
                VALUES (%s, %s) N/A N/A N/A N/A N/A cur execute sql N/A jid N/A N/A N/A psycopg2 extras Json load N/A N/A N/A N/A psycopg2 IntegrityError N/A N/A N/A save_minions N/A N/A jid minions N/A N/A N/A 
    Included for API consistency
     N/A N/A get_load N/A N/A jid N/A N/A N/A 
    Return the load data that marks a specified jid
     N/A N/A _get_serv ret None commit True cur N/A N/A sql SELECT load FROM jids WHERE jid = %s; N/A N/A N/A cur execute sql N/A jid N/A data N/A N/A cur fetchone N/A data N/A N/A N/A data N/A 0 N/A N/A N/A get_jid N/A N/A jid N/A N/A N/A 
    Return the information returned when the specified job id was executed
     N/A N/A _get_serv ret None commit True cur N/A N/A sql SELECT id, full_ret FROM salt_returns
                WHERE jid = %s N/A N/A N/A cur execute sql N/A jid N/A data N/A N/A cur fetchall N/A ret N/A N/A data N/A N/A N/A minion full_ret data N/A N/A N/A ret N/A minion full_ret N/A ret N/A get_fun N/A N/A fun N/A N/A N/A 
    Return a dict of the last function called for all minions
     N/A N/A _get_serv ret None commit True cur N/A N/A sql SELECT s.id,s.jid, s.full_ret
                FROM salt_returns s
                JOIN ( SELECT MAX(`jid`) as jid
                    from salt_returns GROUP BY fun, id) max
                ON s.jid = max.jid
                WHERE s.fun = %s
                 N/A N/A N/A cur execute sql N/A fun N/A data N/A N/A cur fetchall N/A ret N/A N/A data N/A N/A N/A minion _ full_ret data N/A N/A N/A ret N/A minion full_ret N/A ret N/A get_jids N/A N/A N/A N/A N/A 
    Return a list of all job ids
     N/A N/A _get_serv ret None commit True cur N/A N/A sql SELECT jid, load
                FROM jids N/A N/A N/A cur execute sql N/A data N/A N/A cur fetchall N/A ret N/A N/A N/A jid load data N/A N/A N/A ret N/A jid N/A N/A N/A N/A salt utils jid format_jid_instance jid load N/A ret N/A get_minions N/A N/A N/A N/A N/A 
    Return a list of minions
     N/A N/A _get_serv ret None commit True cur N/A N/A sql SELECT DISTINCT id
                FROM salt_returns N/A N/A N/A cur execute sql N/A data N/A N/A cur fetchall N/A ret N/A N/A minion data N/A N/A N/A N/A ret append N/A minion N/A 0 N/A ret N/A prep_jid N/A N/A nocache passed_jid N/A False None N/A N/A 
    Do any work necessary to prepare a JID, including sending a custom id
     N/A N/A N/A passed_jid None passed_jid N/A N/A N/A N/A salt utils jid gen_jid N/A