community.clickhouse.clickhouse_row_policy module – Creates, removes or modify a ClickHouse row policy using the clickhouse-driver Client interface

Note

This module is part of the community.clickhouse collection (version 2.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.clickhouse. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.clickhouse.clickhouse_row_policy.

New in community.clickhouse 2.2.0

Synopsis

  • This module allows you to manage ClickHouse row policies. It can create, remove or modify row policies based on the provided parameters. The module uses the clickhouse-driver Client interface to interact with the ClickHouse database.

Requirements

The below requirements are needed on the host that executes this module.

  • clickhouse-driver

Parameters

Parameter

Comments

apply_to

list / elements=string

The users or roles to which the row policy applies.

Default: []

apply_to_all

boolean

Whether the row policy applies to all users or roles.

Choices:

  • false ← (default)

  • true

apply_to_except

list / elements=string

The users or roles to which the row policy does not apply. Can only be used if apply_to_all is true.

Default: []

client_kwargs

dictionary

Any additional keyword arguments you want to pass to the Client interface when instantiating its object.

Default: {}

cluster

string

The name of the cluster where the row policy is defined. If not provided, the row policy will be managed on the local server.

database

string / required

The name of the database where the row policy is defined.

login_db

string

The same as the Client(database='...') argument.

If not passed, relies on the driver’s default argument value.

login_host

string

The same as the Client(host='...') argument.

Default: "localhost"

login_password

string

The same as the Client(password='...') argument.

If not passed, relies on the driver’s default argument value.

login_port

integer

The same as the Client(port='...') argument.

If not passed, relies on the driver’s default argument value.

login_user

string

The same as the Client(user='...') argument.

If not passed, relies on the driver’s default argument value.

Be sure your the user has permissions to read the system tables listed in the RETURN section.

name

string / required

The name of the row policy to manage.

restrictive

boolean

Whether the row policy is restrictive.

Choices:

  • false ← (default)

  • true

state

string

Whether the row policy should be present or not.

If present, the module will create or update the row policy to match the provided parameters.

If absent, the module will remove the row policy if it exists.

Choices:

  • "present" ← (default)

  • "absent"

success_on

list / elements=integer

added in community.clickhouse 2.2.0

List of server error codes that will be treated as success, otherwise throw errors.

Default: [497]

table

string

The name of the table where the row policy is defined. Can be *,

Default: "*"

using

string

The condition that defines the row policy. This is a required parameter when state=present.

Attributes

Attribute

Support

Description

check_mode

Support: full

Supports check_mode.

idempotent

Support: full

When run twice in a row outside check mode, with the same arguments, the second invocation indicates no change.

Notes

Note

  • See the clickhouse-driver documentation for more information about the driver interface.

Examples

- name: Create a row policy for a specific table
  community.clickhouse.clickhouse_row_policy:
    name: "policy1"
    database: "test_db"
    table: "test_table"
    using: "a = 1"
    restrictive: true
    apply_to: ["user1", "user2"]

- name: Create a row policy that applies to all users except one
  community.clickhouse.clickhouse_row_policy:
    name: "policy2"
    database: "test_db"
    table: "test_table"
    using: "b = 1"
    apply_to_all: true
    apply_to_except: ["user3"]

- name: Remove a row policy
  community.clickhouse.clickhouse_row_policy:
    name: "policy1"
    database: "test_db"
    table: "test_table"
    state: "absent"

- name: Create a row policy for all tables in a database
  community.clickhouse.clickhouse_row_policy:
    name: "policy3"
    database: "test_db"
    table: "*"
    using: "c = 1"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

executed_statements

list / elements=string

Data-modifying executed statements.

Returned: on success

Sample: ["CREATE ROW POLICY `test_policy` ON `test_db`.`test_table` USING `c` = 1 AS PERMISSIVE TO `user1`, `user2`"]

Authors

  • Rafal Kozlowski (@rkozlo)