Setup and configure PgAdmin with servers and scripts

Morning all, I am looking around at ways in which i can leverage ansible in order to automate a PGAdmin setup in docker to make configuring it much simpler.

The system we have now is:

docker-compose to build pgadmin and set up with it’s username and password.

then manually:
Add each server with it’s own port number - 9 instances of this
Then go into each server and execute a query to set everything up - again 9 instances of this
each server has it’s own port, but the username and password are the same throughout as it’s only for connecting to Azure DevOps and an internal process for end to end testing

What i would like to achieve is that I setup a playbook that will be able to automate that entire setup so that we can tear down the container simply, then bring it all back up again with fresh servers and ready to go without then needing to query each db afterwards.

Eventually, my aim will be to use Ansible to setup and configure the 21 other containers we use as part of the same process but without the pgadmin side of things being automated the rest are relatively low priority to figure out as they are simple images.

My question is, can the PGAdmin server setup be done in Ansible as I would like?

I know that pgadmin themselves do have a way to use a servers.json but I cannot include a password in this file which may make that pointless to try, then as well as this I do need to be able to go into each of the servers and execute their reset query so it looked more like something Ansible would be better for anyway as I could then roll all of the other containers into a single process.


1 Like

Welcome @bunglehaze! As you can probably tell, we’re still just setting all this up, so thanks for being the first to ask a question :slightly_smiling_face:.

As this is new, it might take a short while for us to get eyeballs on this. I’ll poke some of the Postgres folks I know and see if we can get you an answer - stay tuned! Oh, and go say hi in Introduce yourself! while you wait :wink:

1 Like

@bunglehaze if this is the main issue, you could try to store the password in a file and use ansible-vault to encrypt the file.

Than you can create a template for that json file, use the variable there, and load the encrypted vault file in the playbook using, for example, the vars_files: keyword.

As the vars file will be encrypted, ansible will ask you to input a password when you run the playbook (see the vault docs above to make ansible show the prompt).

Does it sound like a solution?

Thanks for the reply, I will look into it but my guess is no - not because of the solution but the restriction in pgadmin itself limiting any use of the password field. I think because of this line I need to look at Ansible doing the whole process for me instead of working with the pgadmin solution

Password fields cannot be imported or exported.

Yeah, that sounds like a blocker for PgAdmin. There’s a pretty active group working on the community.postgresql collection, so dropping down to the PostgreSQL level and setting up the databases directly with Ansible sounds better.

Docs for the collection: Community.Postgresql — Ansible Documentation

Let us know how you get on, or if you need more help!

Hi @bunglehaze! It looks like the post might be solved - could you check to see if my response worked for you?

If so, it would be super helpful if you could click the :heavy_check_mark: on their post to accept the solution - it recognises the input of others, helps our volunteers find new issues to answer, and keeps the forum nice and tidy.

(this is template reply, do feel free to reply if I’ve misunderstood the situation!)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.