Working with pairs of servers

Hello there,

I’ve got the general gist of Ansible now, however for this project I’m working on… we have the following scenario:

I want a single playbook, to work for an unlimited amount of hosts within two groups, a webserver group and a database group, one web server should be married up to one database server.

I see I can do something like:

[webserver]
web1 dbserver=db1
web2 dbserver=db2

[dbserver]
db1
db2

And this is fine… but what I’d like to do then, is to generate passwords and store them based upon the hostnames,

so something like credentials/db1/.mysqlpassword and then use this, within web1’s tasks - But making sure this would dynamically work with web2 and db2.

The end goal is to basically have an application server playbook, where the web server is installed on web1 along with the application, such as wordpress or Magento, and it’s database is configured on the db1… The installation of the app, should be able to obtain the passwords for db1, using said variable.

I hope this makes sense, I’m just not sure how to go about it.

Any advice or guidance is appreciated.

Regards,

Matt