Task launch playbook with variables and --limit

30 views
Skip to first unread message

Pierre Mavro

unread,
May 25, 2017, 1:34:41 AM5/25/17
to Ansible Project
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

J Hawkesworth

unread,
May 25, 2017, 9:39:24 AM5/25/17
to Ansible Project
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

Pierre Mavro

unread,
May 25, 2017, 12:35:01 PM5/25/17
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages