How can i specify the same target host twice or more in my playbook ?

I have a situation for which we have decided to allow multiple instances of the same app to run on same host machines. I do not want to modify my playbook or inventory to incorporate this temporary hack and was wondering if i can do that simply by modifying host list and some of the variables.
So i need to know two main things:

  1. Is there a way i can repeat a target host in my playbook ? I have tried repeating the hostname in the comma separated list but that doesn’t work

  2. How can i override some variables for this repeated host ?

I think you are going to have to change, or at least add something to do this.

I would do this by adding a temporary inventory file and group vars.

If you have inventory with groups like

`
[webservers]
host1 app_folder=/opt/instance1

[database]
host1 app_folder=/opt/instance2
`

then you can have a playbook that does something like the following:

`
hosts: webservers:
roles:

  • install_app

hosts: database
roles:

  • install_app
    `

if install_app uses app_folder
as the installation dir for app then you can get 2

Don’t forget you can set defaults in your role so that you only have to provide an override for the hosts that need it.

I have an inventory file which has all the same group names as my test and production inventories, but only 1 actual host, which points at a virtual machine which I can revert back to a ‘blank’ snapshot. I use this a lot for developing my provisioning playbooks.

Hope this helps,

Jon