Task launch playbook with variables and --limit

Hi,

I have to run something like this in a playbook task:

ansible-playbook sites/playbook.yml --limit=server1,server2

I would like to include this playbook in another playbook. How to add the --limit parameter:

`

  • name: my run list
    hosts: localhost
    connection: local
    gather_facts: False
    tasks:
  • include: sites/playbook.yml
  • name: my other tasks

    `

The --limit parameter content is generated on the fly, so I don’t know in advance the servers where the playbook will be applied.

Any ideas ?

Thanks

How about you add server1 and server2 to a group in your inventory - something like this

[application_servers] server1 server2

and then change sites/playbook.yml so it does

hosts: application_servers

instead of

hosts: all

If you want to run the same playbook on different server types, you can specify multiple host groups in your ‘hosts’ line

hosts: application_servers:webservers:database_servers

Hope this helps

Jon

Hi Jon,

Thanks for the answer but it’s not dynamic, as I said, I don’t know in advance which will be the servers where the playbook should run on.

Any idea ?

Thanks