inventory file generated following a playbook run

Hello,
I want to deploy on 2 servers an application and then to deploy an apache server and configuring it.
My issue is that to deploy the Apache server, I need to know the servers names and ports, I have these informations when running the installation of the application, I don’t want to repeat these information manually in a new inventory file. Is there a way to gather these parameters from a playbook to an inventory file in an automatic way ?

I do run a playbook with an inventory file with limits described this way:


[DV70_DEV1]
DV70_DEV12 ansible_host=server1 ansible_user=dv70 product=‘WEB’ instance=‘1’
DV70_DEV12 ansible_host=server2 ansible_user=dv70 product=‘SRV’ instance=‘2’

[DV70_DEV2]
DV70_DEV21…
DV70_DEV22 …

I would like to either have another role or play in this playbook, but that needs the parameters set previously.
That means I need to generate a new inventory file with the following lines:
[DV70_DEV1]
env=‘dv70’ webserver=‘server1’ webinst=‘1’ srvserver=‘server2’ srvinst=‘2’

and so on for all the limits previously deploed by the 1st playbook.

  • So is there a way to create an inventory file when runnng a playbook.
  • I didn’t understand about a dynamic inventory script, but it does not seem to be a way to proceed.
  • I am not sure about delegating_to as the host I will deply then the 2nd role depends on parameters

Any clue about how to proceed ?

regards

I think my need is the following:

I do run a playbook, first on a play on [servers] hosts, I would like at the end of this play to use the meta: refresh_inventory so a dynamic invetory script would generate [Apache] hosts in my inventory file and the 2nd play would be depoying on the [Apache] hosts.
So is it possible that I gather parameters from my 1st play to be in the input of a Dynamic inventory script ? I don’t find detailed documentation about the use of such a script

Regards

add_host might solve my issue