# Task launch playbook with variables and --limit

**URL:** <https://forum.ansible.com/t/task-launch-playbook-with-variables-and-limit/24575>\
**Category:** Ansible Project\
**Created:** [May 25, 2017, 5:34am UTC](https://forum.ansible.com/t/task-launch-playbook-with-variables-and-limit/24575 "2017-05-25T05:34:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Mavro](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pierre\_Mavro](https://forum.ansible.com/u/Pierre_Mavro)\
**Post date:** [May 25, 2017, 5:34am UTC](https://forum.ansible.com/t/task-launch-playbook-with-variables-and-limit/24575/1 "2017-05-25T05:34:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [May 25, 2017, 1:39pm UTC](https://forum.ansible.com/t/task-launch-playbook-with-variables-and-limit/24575/2 "2017-05-25T13:39:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pierre\_Mavro](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pierre\_Mavro](https://forum.ansible.com/u/Pierre_Mavro)\
**Post date:** [May 25, 2017, 4:35pm UTC](https://forum.ansible.com/t/task-launch-playbook-with-variables-and-limit/24575/3 "2017-05-25T16:35:01Z")

</div>

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
