# Question concerning multiple -hosts: entries in a playbook

**URL:** <https://forum.ansible.com/t/question-concerning-multiple-hosts-entries-in-a-playbook/25879>\
**Category:** Ansible Project\
**Created:** [October 31, 2017, 6:40pm UTC](https://forum.ansible.com/t/question-concerning-multiple-hosts-entries-in-a-playbook/25879 "2017-10-31T18:40:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.haney](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@mark.haney](https://forum.ansible.com/u/mark.haney)\
**Post date:** [October 31, 2017, 6:40pm UTC](https://forum.ansible.com/t/question-concerning-multiple-hosts-entries-in-a-playbook/25879/1 "2017-10-31T18:40:02Z")

</div>

There might be a better way to do this, but I’m unaware of it, so I’m asking the list. I have a playbook that has two parts to it:

1. Pulls branch from git repo to the localhost (ie the Ansible server)  
1a. compiles the code (it’s a PHAR file, so nothing too onerous)
2. Pushes the code to our external servers.

Part 1/1a has a hosts: entry of ‘localhost’ and part 2 has a hosts: entry for our external servers that are getting the updated code.

My question is, is there a way to abstract the second hosts: line so I can specify specific hosts/groups? IOW, if I set that hosts: line to ‘production’, is there a way to specify on the command line -i dbservers or other subset instead of manually editing that line every time?

Second question, if the above question is just wrong/bad/not sane, is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 31, 2017, 6:53pm UTC](https://forum.ansible.com/t/question-concerning-multiple-hosts-entries-in-a-playbook/25879/2 "2017-10-31T18:53:41Z")

</div>

You can set the 2nd play like this:

- hosts: '{{target|default('devel')}}'

then call it:

ansible-playbook ... -e 'target=production'

---

<div class="post-metadata">

**Author:** ![mark.haney](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@mark.haney](https://forum.ansible.com/u/mark.haney)\
**Post date:** [October 31, 2017, 6:59pm UTC](https://forum.ansible.com/t/question-concerning-multiple-hosts-entries-in-a-playbook/25879/3 "2017-10-31T18:59:23Z")

</div>

Huh. I hadn't thought about using that method. I'll give it a shot. Thanks.
