Getting syntax error

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.

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

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

gather_facts: no

become: true

vars_files:

As per my understanding roles will not require and specific tags

  • hosts: “{{ groups[‘all’][0] }}”
    gather_facts: no
    become: true

vars_files:

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?

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