Centralize database configuration into a single reusable list#550
Conversation
Define a canonical `databases` list in database.yml with feature tags, replacing scattered conditional enumeration across consumers. A computed `all_databases` filters by enabled_features, and custom Jinja2 filters derive postgresql_databases/postgresql_users from it — eliminating static list duplication and the merge pre_tasks in deploy.yaml. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
639ba13 to
3441151
Compare
| ssl_ca: "{{ foreman_database_ssl_ca }}" | ||
| feature: foreman | ||
| - name: candlepin | ||
| database: "{{ candlepin_database_name }}" |
There was a problem hiding this comment.
Not a blocker but more of a thought: We are gating on features, which means if the katello feature is there then only we will have pulp and candlepin databases, if its missing we don't have those, which is fine by today as we only have katello flavor, but in case of foreman-proxy-content flavor, we only will need pulp db not candlepin and then this becomes a issue,
There was a problem hiding this comment.
That's being filtered later in:
all_databases: >-
{{ databases | selectattr('feature', 'in', enabled_features) | list }}
There was a problem hiding this comment.
what i meant was enabled_features never know what pulp and candlepin is, only katello. thus no gating on pulp and candlepin
There was a problem hiding this comment.
Right, we have no pulp or candlepin feature (yet), which I think is also something we need/want to tackle for the tests too. Once we introduce those features, we can adjust here.
sjha4
left a comment
There was a problem hiding this comment.
Tested foremanctl check to make sure all DBs are made available to it and it works as advertised..Deploy has worked well with the change deploying all IoP DBs correctly.
Do we want a developer doc change to go with this for devs/agents to follow?
3441151 to
8c271df
Compare
There was a problem hiding this comment.
Do we need to refactor this similarly?
I do not think so, I believe this is discoverable as a internal mechanism. |
The development playbooks load src/vars/database.yml which now uses custom filters (to_postgresql_databases, to_postgresql_users). Without this path, playbooks run from the development directory fail with "No filter named" errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8c271df to
8e4ce37
Compare
|
Ignoring EL10 test results as there is an issue with the VM image affecting all tests right now. |
Summary
Database configuration was duplicated across multiple consumers — each playbook and role that needed the list of databases would manually enumerate them with conditional logic for features like IOP. Adding a new database service meant editing every consumer.
This PR:
databaseslist indatabase.ymlwhere each entry is tagged with afeature(e.g.foreman,katello,iop)all_databasesvariable that filtersdatabasesbyenabled_featuresto_postgresql_databasesandto_postgresql_userscustom Jinja2 filters that derive the postgresql role's input lists fromall_databasesdatabase_iop.ymlintodatabase.yml— one file for all database configurationpre_tasksmerge block fromdeploy.yaml(no longer needed)check_database_connectionto loop overchecks_databases(a namespaced variable passed from the checks role) instead of a hardcoded inline listMotivation
Every new command that needs database awareness (backup, restore, upgrade, health-check) was forced to repeat the same conditional enumeration pattern: foreman always, candlepin+pulp if katello, 5 IOP databases if iop. This was already duplicated in
deploy.yaml,checks.yaml, andcheck_database_connection, and would only grow worse.Design
The
databaseslist captures the full connection info for each database (name, host, port, user, password, ssl_mode, ssl_ca). Thefeaturefield maps toenabled_featuresso the list self-filters. Custom filters project this into the{name, owner}and{name, password}shapes that the postgresql role expects.Changes
src/vars/database.ymldatabases/all_databases, replaced staticpostgresql_databases/postgresql_userswith filter-derived computed varssrc/vars/database_iop.ymldatabase.yml)src/filter_plugins/foremanctl.pyto_postgresql_databasesandto_postgresql_usersfilterssrc/playbooks/deploy/deploy.yamlpre_tasks, passchecks_databasesto checks rolesrc/playbooks/checks/checks.yamlchecks_databasesto checks rolesrc/roles/check_database_connection/tasks/main.yamlchecks_databasessrc/roles/check_database_connection/tasks/check.yamldbname→database,sslmode→ssl_mode,ca_cert→ssl_ca)src/roles/checks/defaults/main.ymlchecks_databases: []defaultdevelopment/playbooks/deploy-dev/deploy-dev.yamlinclude_varsfor deleteddatabase_iop.ymlTest plan
cd src; ansible-lintpassescd development; ansible-lintpasses--tuning developmentand verify postgresql databases and users are created correctlyforemanctl checkswithdatabase_mode: externaland verify all databases are checkedforge deploy-dev) still works with its test DB and SUPERUSER overrides