community.cockroachdb.cockroachdb_query (0.3.1) — module

Run queries in a CockroachDB database

| "added in version" 0.1.0 of community.cockroachdb"

Authors: Andrew Klychkov (@Andersson007)

Install collection

Install with ansible-galaxy collection install community.cockroachdb:==0.3.1


Add to requirements.yml

  collections:
    - name: community.cockroachdb
      version: 0.3.1

Description

Runs arbitrary queries in a CockroachDB database.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run simple select query in acme db
  community.cockroachdb.cockroachdb_query:
    login_db: acme
    query: SELECT version()
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Print information returned from the previous task
  ansible.builtin.debug:
    var: result
    verbosity: 2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run simple select query in acme db in the verify-full SSL mode
  community.cockroachdb.cockroachdb_query:
    login_host: 192.168.0.10
    login_db: acme
    query: SELECT version()
    ssl_mode: verify-full
    ssl_root_cert: /tmp/certs/ca.crt
    ssl_cert: /tmp/certs/client.root.crt
    ssl_key: /tmp/certs/client.root.key
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run query in acme db using positional args and non-default credentials
  community.cockroachdb.cockroachdb_query:
    login_db: acme
    login_user: django
    login_password: mysecretpass
    query: SELECT * FROM acme WHERE id = %s AND story = %s
    positional_args:
    - 1
    - test
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run query in test_db using named args
  community.cockroachdb.cockroachdb_query:
    login_db: test_db
    query: SELECT * FROM test WHERE id = %(id_val)s AND story = %(story_val)s
    named_args:
      id_val: 1
      story_val: test

Inputs

    
query:
    description:
    - SQL query to run. Variables can be escaped with psycopg2 syntax U(http://initd.org/psycopg/docs/usage.html).
    type: str

ssl_key:
    description:
    - Specifies the location for the secret key used for the client certificate.
    type: path

login_db:
    description:
    - Database name to connect to.
    type: str

ssl_cert:
    description:
    - Specifies the file name of the client SSL certificate.
    type: path

ssl_mode:
    choices:
    - allow
    - disable
    - prefer
    - require
    - verify-ca
    - verify-full
    default: prefer
    description:
    - Determines whether or with what priority a secure SSL TCP/IP connection will be
      negotiated with the server.
    - Refer to U(https://www.postgresql.org/docs/current/static/libpq-ssl.html) for more
      information on the modes.
    - Default of C(prefer) matches libpq default.
    type: str

rows_type:
    choices:
    - dict
    - tuple
    default: dict
    description:
    - If set to C(tuple), rows in the I(query_result) return value will be of the tuple
      type.
    - Returns dictionaries by default.
    type: str

login_host:
    default: localhost
    description:
    - Host running the database.
    type: str

login_port:
    default: 26257
    description:
    - Database port to connect to.
    type: int

login_user:
    default: root
    description:
    - User name used to connect to the database.
    type: str

named_args:
    description:
    - Dictionary of key-value arguments to pass to the query.
    - Mutually exclusive with I(positional_args).
    type: dict

ssl_root_cert:
    description:
    - Specifies the name of a file containing SSL certificate authority (CA) certificate(s).
    - If the file exists, the server's certificate will be verified to be signed by one
      of these authorities.
    type: path

login_password:
    description:
    - The password of the I(login_user).
    type: str

positional_args:
    description:
    - List of values to be passed as positional arguments to the query.
    - Mutually exclusive with I(named_args).
    elements: raw
    type: list

login_unix_socket:
    description:
    - Path to a directory containing a Unix domain socket for local connections.
    type: path

Outputs

query:
  description:
  - Executed query containing substituted arguments.
  returned: always
  sample: SELECT * FROM bar
  type: str
query_result:
  description:
  - List of dicts representing returned rows. When the I(rows_type) option is set
    to C(tuple), it will consist of tuples.
  elements: dict
  returned: always
  sample:
  - version: CockroachDB CCL v21.1.6 (x86_64-unknown-linux-gnu, built 2021/07/20 15:30:39,
      go1.15.11)
  type: list
rowcount:
  description:
  - Number of produced or affected rows.
  returned: changed
  sample: 5
  type: int
statusmessage:
  description:
  - Attribute containing the message returned by the command.
  returned: always
  sample: INSERT 0 1
  type: str