postgresql_cluster icon indicating copy to clipboard operation
postgresql_cluster copied to clipboard

Hardcoded vars file path makes it harder to use versioned inventories

Open n-borges opened this issue 1 year ago • 2 comments

Hello everyone, I might be wrong, but it seems to me that the playbooks search for variables in hardcoded paths (namely vars/main.yml). This, I think, makes it a bit harder to use this (awesome!) playbooks with multiple inventories. Consider the following usecase:

  • I have to deploy multiple clusters with multiple configurations for different customers;
  • I want to version each inventory separately;
  • I want to keep my deployments updated and use this repo;

If the variables files paths were not hardcoded, i could simply clone the repo, keep my inventories in dedicated directories and run ansible-playbook <playbook name> -i <inventory dir path>, and let Ansible lookup variables in paths relative to the inventory directory.

Don't you think this would make for a slightly better user experience? Would you be open to a MR to make this kind of change?

Thanks

n-borges avatar Feb 21 '24 10:02 n-borges

Had same consideration and moved all (needed by me) variables to additional file, f.ex.: custom_config.yml and use this configuration during playbook run, like: ansible-playbook -i my_inventory -e@custom_config.yml deploy_pgcluster.yml

redy01 avatar Feb 21 '24 11:02 redy01

Hello @n-borges

as @redy01 (thanks!) has already correctly pointed out, you can redefine variables at the --extra-vars level, or at the inventory vars level.

In a future version of postgresql_cluster there will be a docker image that can be used as an installer, and there will mainly be used extra-vars, examples https://github.com/vitabaks/postgresql_cluster/pull/464

vitabaks avatar Feb 21 '24 11:02 vitabaks