# Ansible 2.5 is not accepting dynamic hosts variable

**URL:** <https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121>\
**Category:** Ansible Project\
**Created:** [March 26, 2018, 11:25pm UTC](https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121 "2018-03-26T23:25:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rummandba](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rummandba](https://forum.ansible.com/u/rummandba)\
**Post date:** [March 26, 2018, 11:25pm UTC](https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121/1 "2018-03-26T23:25:26Z")

</div>

Hi,

I have upgraded to Ansible 2.5 right now and facing an issue with variable hosts such as:

```auto

---
- hosts: "{{ dbhosts }}"
 gather_facts: false
 vars_prompt:
 - name: dbhosts
 prompt: "Which hosts would you like to run?"
 private: no
 default: all

 tasks:
 - debug:
 var: hostvars

```

```auto

```

`  
ERROR! The field ‘hosts’ has an invalid value, which includes an undefined variable. The error was: ‘dbhosts’ is undefined The error appears to have been in ‘/ansible/playbooks/tester.yaml’: line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: — - hosts: “{{ dbhosts }}” ^ here We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance: with\_items: - {{ foo }}

`

```auto

```

```auto
The same playbook was running fine with Ansible 2.4.

```

```auto
Is there any specific change that I should follow in Ansible 2.5?

```

```auto
Please advise. 

```

```auto

```

```auto
Thanks & Regards.

```

---

<div class="post-metadata">

**Author:** ![dbpiv](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dbpiv](https://forum.ansible.com/u/dbpiv)\
**Post date:** [April 14, 2018, 1:20pm UTC](https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121/2 "2018-04-14T13:20:58Z")

</div>

Did you ever resolve this issue? Or find an acceptable workaround?

I have the same issue and that is a core part of many of our playbooks.

DP

---

<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:** [April 17, 2018, 8:39am UTC](https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121/3 "2018-04-17T08:39:42Z")

</div>

I suggest making ‘dbhosts’ a group name in your inventory, then you can have

hosts: dbhosts

in your playbook, and its settled that what happens in that playbook will only happen on hosts in the group ‘dbhosts’

If you still need to set hosts dynamically, consider defaulting, like this

hosts: “{{dbhosts|default(‘dbhosts’)”

That way you can override the default hosts by passing -e ‘dbhosts=some-other-host’ to your ansible-playbook command, if you need to.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![dbpiv](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dbpiv](https://forum.ansible.com/u/dbpiv)\
**Post date:** [April 17, 2018, 3:21pm UTC](https://forum.ansible.com/t/ansible-2-5-is-not-accepting-dynamic-hosts-variable/27121/4 "2018-04-17T15:21:42Z")

</div>

Thanks for the reply. I found the issue and it is a bug in 2.5.0 and was reported here: [https://github.com/ansible/ansible/issues/37984](https://github.com/ansible/ansible/issues/37984)

The fix is also linked in the bug report at: [https://github.com/ansible/ansible/pull/38000](https://github.com/ansible/ansible/pull/38000). I pulled the fixed file and my install of 2.5.0 is now working as expected in terms of vars\_prompt.

Thanks for the help.

dp
