postgresql-user-exists
Example:
# Create PostgreSQL user 'freckles' with password 'password123' - postgresql-user-exists: db_user: freckles db_user_password: password123
Description
Ensures a database user with the provided name is present on a PostgreSQL server.
The PostgreSQL service itself won't be installed, use the 'postgresql-service' frecklet before this if necessary.
Resources
Variables
Name | Type | Default | Description |
---|---|---|---|
|
string | -- | The name of the database user ('role' in postgres). Required |
|
string | -- | The password needs to be passed in hashed form, please check the [Postgresql documentation]( |
Examples
Example 1
Create PostgreSQL user 'freckles' with password 'password123'
Code
- postgresql-user-exists: db_user: freckles db_user_password: password123
Description
This isn't all that useful on it's own, without the user having access to anything. You probably want the 'postgresql-database-exists' frecklet, which incorporates this one.
Code
doc: short_help: Installs PostgreSQL (if necessary), and makes sure a specified database exists. help: | Ensures a database user with the provided name is present on a PostgreSQL server. The PostgreSQL service itself won't be installed, use the 'postgresql-service' frecklet before this if necessary. examples: - title: Create PostgreSQL user 'freckles' with password 'password123' desc: | This isn't all that useful on it's own, without the user having access to anything. You probably want the 'postgresql-database-exists' frecklet, which incorporates this one. vars: db_user: freckles db_user_password: password123 references: Postgresql createuser documentation: https://www.postgresql.org/docs/current/app-createuser.html Postgresql 'create role' documentation: https://www.postgresql.org/docs/current/sql-createrole.html Ansible postgresql_user documentation: https://docs.ansible.com/ansible/latest/modules/postgresql_user_module.html Ansible postgresql_db documentation: https://docs.ansible.com/ansible/latest/modules/postgresql_db_module.html args: db_user: doc: short_help: The name of the database user ('role' in postgres). type: string required: true db_user_password: doc: short_help: The (hashed) password for the database user ('role' in PostgreSQL). help: | The password needs to be passed in hashed form, please check the [Postgresql documentation]( type: string required: false secret: true meta: tags: - postgresql - database frecklets: - task: become: true become_user: postgres frecklet: name: postgresql_user type: ansible-module skip: '{{:: db_user | true_if_empty ::}}' properties: elevated: true idempotent: true internet: false desc: short: "create postgresql user '{{:: db_user ::}}'" references: "'postgresql_user' Ansible module": https://docs.ansible.com/ansible/latest/modules/postgresql_user_module.html vars: name: '{{:: db_user ::}}' password: '{{:: db_user_password | postgresql_password_hash(db_user) ::}}' encrypted: true
frecklecute postgresql-user-exists --help Usage: frecklecute postgresql-user-exists [OPTIONS] Ensures a database user with the provided name is present on a PostgreSQL server. The PostgreSQL service itself won't be installed, use the 'postgresql- service' frecklet before this if necessary. Options: --db-user DB_USER The name of the database user ('role' in postgres). [required] --db-user-password DB_USER_PASSWORD The (hashed) password for the database user ('role' in PostgreSQL). --help Show this message and exit.
# -*- coding: utf-8 -*- # # module path: pycklets.postgresql_user_exists.PostgresqlUserExists # from dataclasses import dataclass from pyckles import AutoPycklet from typing import * # noqa @dataclass class PostgresqlUserExists(AutoPycklet): """Ensures a database user with the provided name is present on a PostgreSQL server. The PostgreSQL service itself won't be installed, use the 'postgresql-service' frecklet before this if necessary. Args: db_user: The name of the database user ('role' in postgres). db_user_password: The (hashed) password for the database user ('role' in PostgreSQL). """ FRECKLET_ID = "postgresql-user-exists" db_user: str = None db_user_password: str = None def __post_init__(self): super(PostgresqlUserExists, self).__init__(var_names=["db_user", "db_user_password"]) frecklet_class = PostgresqlUserExists
# -*- coding: utf-8 -*- # # module path: pycklets.postgresql_user_exists.PostgresqlUserExists # from pyckles import AutoPycklet class PostgresqlUserExists(AutoPycklet): """Ensures a database user with the provided name is present on a PostgreSQL server. The PostgreSQL service itself won't be installed, use the 'postgresql-service' frecklet before this if necessary. Args: db_user: The name of the database user ('role' in postgres). db_user_password: The (hashed) password for the database user ('role' in PostgreSQL). """ FRECKLET_ID = "postgresql-user-exists" def __init__(self, db_user=None, db_user_password=None): super(PostgresqlUserExists, self).__init__(var_names=["db_user", "db_user_password"]) self._db_user = db_user self._db_user_password = db_user_password @property def db_user(self): return self._db_user @db_user.setter def db_user(self, db_user): self._db_user = db_user @property def db_user_password(self): return self._db_user_password @db_user_password.setter def db_user_password(self, db_user_password): self._db_user_password = db_user_password frecklet_class = PostgresqlUserExists