# Getting syntax error

**URL:** <https://forum.ansible.com/t/getting-syntax-error/33710>\
**Category:** Ansible Project\
**Created:** [September 1, 2020, 9:43am UTC](https://forum.ansible.com/t/getting-syntax-error/33710 "2020-09-01T09:43:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramu\_Mathi](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@Ramu\_Mathi](https://forum.ansible.com/u/Ramu_Mathi)\
**Post date:** [September 1, 2020, 9:43am UTC](https://forum.ansible.com/t/getting-syntax-error/33710/1 "2020-09-01T09:43:04Z")

</div>

I am getting the following the error with my config

ERROR! The field ‘hosts’ has an invalid value, which includes an undefined variable. The error was: list object has no element 0

The error appears to be in ‘/Users/ramumathi/Desktop/workspace/RMQ/ansible-rmq-ha/playbook.yml’: line 91, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- hosts: “{{ groups[‘all’][0] }}”

^ 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 }}

Should be written as:

with\_items:

- “{{ foo }}”

ansible-playbook --version

ansible-playbook 2.8.1

python version = 2.7.16 (default, Dec 13 2019, 18:00:32) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s

Can you please let me know why I am getting this error.

Thanks,

Ramu.

---

<div class="post-metadata">

**Author:** ![Kundan\_Singh](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kundan\_Singh](https://forum.ansible.com/u/Kundan_Singh)\
**Post date:** [September 1, 2020, 2:23pm UTC](https://forum.ansible.com/t/getting-syntax-error/33710/2 "2020-09-01T14:23:14Z")

</div>

Hi ,

There is a syntax issue in the jinja2 template  
When you are defining hosts there should be space in variable mention in the line

Synatx should appear like below

hosts: “{{ abc }}”

Regards  
Kundan singh

---

<div class="post-metadata">

**Author:** ![Ramu\_Mathi](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@Ramu\_Mathi](https://forum.ansible.com/u/Ramu_Mathi)\
**Post date:** [September 1, 2020, 3:32pm UTC](https://forum.ansible.com/t/getting-syntax-error/33710/3 "2020-09-01T15:32:20Z")

</div>

| 

Hi Singh, This is my configuration and it invokes the below tasks. - hosts: “{{ groups[‘all’][0] }}”

 |
| | 

gather\_facts: no

 |
| | 

become: true

 |
| | 

vars\_files:

 |
| | |

---

<div class="post-metadata">

**Author:** ![Kundan\_Singh](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kundan\_Singh](https://forum.ansible.com/u/Kundan_Singh)\
**Post date:** [September 1, 2020, 7:32pm UTC](https://forum.ansible.com/t/getting-syntax-error/33710/4 "2020-09-01T19:32:58Z")

</div>

As per my understanding roles will not require and specific tags

- hosts: “{{ groups[‘all’][0] }}”  
gather\_facts: no  
become: true

vars\_files:

---

<div class="post-metadata">

**Author:** ![Ramu\_Mathi](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@Ramu\_Mathi](https://forum.ansible.com/u/Ramu_Mathi)\
**Post date:** [September 2, 2020, 4:43am UTC](https://forum.ansible.com/t/getting-syntax-error/33710/5 "2020-09-02T04:43:55Z")

</div>

Singh, We need roles here and we are calling the same way for others and they are working well. Only for this host configuration I am getting that error. Can we deep debug on this?

---

<div class="post-metadata">

**Author:** ![Ramu\_Mathi](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@Ramu\_Mathi](https://forum.ansible.com/u/Ramu_Mathi)\
**Post date:** [September 2, 2020, 5:18pm UTC](https://forum.ansible.com/t/getting-syntax-error/33710/6 "2020-09-02T17:18:04Z")

</div>

Any update on this? Please let me know. I need your help.
