ERROR: provided hosts list is empty

Hello All,

I have a simple .yml file that looks like this.

  • hosts: ‘{{ hosts }}’
    tasks:
  • include: tasks/apt_setup.yml app_user=‘{{ as_user }}’
  • include: tasks/python_setup.yml app_user=‘{{ as_user }}’

And I am invoking this script using the following command:
ansible-playbook -vvv --ask-sudo-pas local_play.yml --extra-vars ‘hosts=localhost app_user=joe’

I get the following error:

ERROR: provided hosts list is empty

What am I doing wrong…

Thanks

try using a variable named 'target', hosts is a keyword and can lead
to confusion, in general do not use variables that overlap with
keywords.

Thanks Brian.

I tried target but go the same error. I also tried to get rid of variable entirely with the following statement

  • hosts: ‘localhost’
    tasks:
  • name: test ping
    ping:

and I still see the same error. Looks like there is some other config file that is causing some issue. Note, that this is specific to a machine and I am not getting this error on another machine. So, am I missing some setting in /etc/ansible/hosts file?

newer ansible versions should 'just work' with localhost, any other
host you want to use should appear in inventory (default is
/etc/ansible/hosts) but you can even define in command line '-i
"hostname,"' < comma is important as it tells ansible it is a list.

That is very strange. The original etc/ansible/hosts file has all lines commented out.

I just added an entry like this

[dummy_hosts]
dummy

And everything starts working perfectly with the original file.

Thanks
Guru