diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml new file mode 100644 index 0000000..448b790 --- /dev/null +++ b/.github/workflows/ansible.yml @@ -0,0 +1,10 @@ +--- +name: CI +on: + push: + workflow_dispatch: +jobs: + ansible-role: + uses: punktDe/shared-workflows/.github/workflows/ansible-role.yml@main + secrets: + galaxy_api_key: ${{ secrets.ANSIBLE_GALAXY_API_KEY }} diff --git a/.github/workflows/generate_readme.yml b/.github/workflows/generate_readme.yml deleted file mode 100644 index c95abdb..0000000 --- a/.github/workflows/generate_readme.yml +++ /dev/null @@ -1,49 +0,0 @@ ---- -name: Generate README.md for the role - -on: - push: - branches: - - '**' - tags-ignore: - - '**' - workflow_dispatch: - -permissions: - contents: write - -jobs: - readme: - name: Generate README.md from argument specs - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install uv - uses: astral-sh/setup-uv@v5 - - - name: Set up Python - run: uv python install - - - name: Install dependencies - run: | - uv -q venv --allow-existing --seed .venv - . .venv/bin/activate - uv -q pip install -r requirements.txt - - - name: Run aar-doc - run: | - . .venv/bin/activate - aar-doc --output-mode replace --config-file .aar-doc.yml . markdown - - - name: Output diff - run: git diff README.md - - - name: Commit and push README - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git add README.md - git diff-index --quiet HEAD || git commit -m "chore: Generate README.md" - git push diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 0313f1e..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,61 +0,0 @@ ---- -name: Test -run-name: Run molecule tests on the role -on: - push: - workflow_dispatch: - -env: - ANSIBLE_ROLES_PATH: roles - ANSIBLE_HASH_BEHAVIOUR: merge - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install uv - uses: astral-sh/setup-uv@v5 - - - name: Set up Python - run: uv python install - - - name: Install dependencies - run: | - uv -q venv --allow-existing --seed .venv - . .venv/bin/activate - uv -q pip install -r requirements.txt - - - name: Run ansible-lint - run: | - . .venv/bin/activate - ansible-lint - - molecule: - strategy: - matrix: - os: [ubuntu-2204, ubuntu-2404, debian-12, debian-13] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install uv - uses: astral-sh/setup-uv@v5 - - - name: Set up Python - run: uv python install - - - name: Install dependencies. - run: | - uv -q venv --allow-existing --seed .venv - . .venv/bin/activate - uv -q pip install -r requirements.txt - ansible-galaxy install -r requirements.yml - - - name: Run molecule - run: | - . .venv/bin/activate - molecule test -p ${{ matrix.os }} diff --git a/README.md b/README.md index d320a15..c512ca1 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ postgresql role for Proserver |---|---|---|---|---| | `version` | Major version of PostgreSQL to install/configure. Ignored on FreeBSD Proservers (version is determined by the system). | int | no | 13 | | `prefix` | | dict of 'prefix' options | no | | -| `users` | Dict of PostgreSQL users to create (key is an arbitrary id, value defines the user). | dict of 'users' options | no | {} | -| `privileges` | Dict of privileges to assign (key is arbitrary id). Each entry grants a role access to a database or object. | dict of 'privileges' options | no | {} | -| `databases` | Dict of databases to create (key is arbitrary id). At least the root database entry is required by defaults. | dict of 'databases' options | no | | +| `users` | Dict of PostgreSQL users to create (key is an arbitrary id, value defines the user). Values should contain: username (str), password (str, optional), role_attributes (dict, optional), hosts (list, optional). | dict | no | | +| `privileges` | Dict of privileges to assign (key is arbitrary id). Each entry grants a role access to a database or object. Values should contain: username (str), database (str), type (str, default: table), objs (str, optional), schema (str, optional), privs (list). | dict | no | | +| `databases` | Dict of databases to create (key is arbitrary id). At least the root database entry is required by defaults. Values should contain: name (str), owner (str), encoding (str, optional), lc_collate (str, optional), lc_ctype (str, optional), template (str, optional), import_file (path, optional). | dict | no | | | `database_defaults` | Defaults applied to database creation when not set per-database. | dict of 'database_defaults' options | no | | | `postgresql.conf` | Key-value options written to the role-managed include file (ansible.conf), included from postgresql.conf. Consult PostgreSQL documentation for valid settings. | dict | no | | | `repository` | Package repository used to install PostgreSQL (Linux/Debian). | dict of 'repository' options | no | | @@ -38,39 +38,7 @@ postgresql role for Proserver |Option|Description|Type|Required|Default| |---|---|---|---|---| -| `config` | Directory for PostgreSQL configuration (e.g. pg_hba.conf, postgresql.conf include). Defaults depend on system; see defaults/main.yaml (e.g. /etc/postgresql/{{ version }}/main/conf.d on Linux). | str | no | | - -#### Options for `postgresql.users` - -|Option|Description|Type|Required|Default| -|---|---|---|---|---| -| `username` | Login name of the user. | str | no | | -| `password` | Password for the user (optional). | str | no | | -| `role_attributes` | Role attributes (e.g. SUPERUSER, CREATEROLE); values are joined for role_attr_flags. | dict | no | | -| `hosts` | List of client addresses (e.g. 127.0.0.1) for which a pg_hba.conf host entry is added. Used together with privileges to allow password authentication from those hosts. | list of 'str' | no | | - -#### Options for `postgresql.privileges` - -|Option|Description|Type|Required|Default| -|---|---|---|---|---| -| `username` | Role name to grant the privilege to. | str | no | | -| `database` | Database the privilege applies to. | str | no | | -| `type` | Type of object (e.g. table, database, schema). | str | no | table | -| `objs` | Object name(s) for the grant (optional for type database). | str | no | | -| `schema` | Schema name (optional). | str | no | | -| `privs` | List of privilege names (e.g. ALL, SELECT, INSERT). | list of 'str' | no | | - -#### Options for `postgresql.databases` - -|Option|Description|Type|Required|Default| -|---|---|---|---|---| -| `name` | Name of the database. | str | no | | -| `owner` | Owner of the database. Use ~ to reference a user from postgresql.users by key (e.g. ~molecule). | str | no | | -| `encoding` | Character encoding (defaults to database_defaults.encoding). | str | no | | -| `lc_collate` | Locale for collation order (defaults to database_defaults.lc_collate). | str | no | | -| `lc_ctype` | Locale for character classification (defaults to database_defaults.lc_ctype). | str | no | | -| `template` | Template database to use (defaults to database_defaults.template). | str | no | | -| `import_file` | Path to a dump file to restore into the database after creation (optional). | path | no | | +| `config` | Directory for PostgreSQL configuration (e.g. pg_hba.conf, postgresql.conf include). Defaults depend on system; see defaults/main.yaml (e.g. /etc/postgresql/{{ postgresql.version }}/main/conf.d on Linux). | str | no | | #### Options for `postgresql.database_defaults` diff --git a/defaults/main.yaml b/defaults/main.yaml index 243a583..fbcfda3 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -42,5 +42,5 @@ postgresql: apt: key_url: https://packagecloud.io/timescale/timescaledb/gpgkey repository: | - deb https://packagecloud.io/timescale/timescaledb/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} main + deb https://packagecloud.io/timescale/timescaledb/{{ ansible_facts['distribution'] | lower }}/ {{ ansible_facts['distribution_release'] }} main package: timescaledb-2-postgresql-{{ postgresql_version }} diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index d7fa9db..40b06e5 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -19,81 +19,24 @@ argument_specs: type: "str" description: - Directory for PostgreSQL configuration (e.g. pg_hba.conf, postgresql.conf include). - - Defaults depend on system; see defaults/main.yaml (e.g. /etc/postgresql/{{ version }}/main/conf.d on Linux). + - Defaults depend on system; see defaults/main.yaml (e.g. /etc/postgresql/{{ postgresql.version }}/main/conf.d on Linux). users: type: "dict" default: {} description: - Dict of PostgreSQL users to create (key is an arbitrary id, value defines the user). - options: - username: - type: "str" - description: Login name of the user. - password: - type: "str" - description: Password for the user (optional). - role_attributes: - type: "dict" - description: Role attributes (e.g. SUPERUSER, CREATEROLE); values are joined for role_attr_flags. - hosts: - type: "list" - elements: "str" - description: - - List of client addresses (e.g. 127.0.0.1) for which a pg_hba.conf host entry is added. - - Used together with privileges to allow password authentication from those hosts. + - "Values should contain: username (str), password (str, optional), role_attributes (dict, optional), hosts (list, optional)." privileges: type: "dict" default: {} description: - Dict of privileges to assign (key is arbitrary id). Each entry grants a role access to a database or object. - options: - username: - type: "str" - description: Role name to grant the privilege to. - database: - type: "str" - description: Database the privilege applies to. - type: - type: "str" - default: "table" - description: Type of object (e.g. table, database, schema). - objs: - type: "str" - description: Object name(s) for the grant (optional for type database). - schema: - type: "str" - description: Schema name (optional). - privs: - type: "list" - elements: "str" - description: List of privilege names (e.g. ALL, SELECT, INSERT). + - "Values should contain: username (str), database (str), type (str, default: table), objs (str, optional), schema (str, optional), privs (list)." databases: type: "dict" description: - Dict of databases to create (key is arbitrary id). At least the root database entry is required by defaults. - options: - name: - type: "str" - description: Name of the database. - owner: - type: "str" - description: - - Owner of the database. Use ~ to reference a user from postgresql.users by key (e.g. ~molecule). - encoding: - type: "str" - description: Character encoding (defaults to database_defaults.encoding). - lc_collate: - type: "str" - description: Locale for collation order (defaults to database_defaults.lc_collate). - lc_ctype: - type: "str" - description: Locale for character classification (defaults to database_defaults.lc_ctype). - template: - type: "str" - description: Template database to use (defaults to database_defaults.template). - import_file: - type: "path" - description: Path to a dump file to restore into the database after creation (optional). + - "Values should contain: name (str), owner (str), encoding (str, optional), lc_collate (str, optional), lc_ctype (str, optional), template (str, optional), import_file (path, optional)." database_defaults: type: "dict" options: diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index d9ef25b..379d05e 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -24,6 +24,8 @@ platforms: <<: *default_platform provisioner: name: ansible + env: + ANSIBLE_ROLES_PATH: ../../roles:../../../:~/.ansible/roles playbooks: converge: ${MOLECULE_PLAYBOOK:-converge.yml} verifier: diff --git a/requirements.txt b/requirements.txt index 94664a8..46920ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ ansible>12.0.0 ansible-lint docker -molecule<25.2.0 +molecule molecule-plugins yamllint requests