Using variable in "hosts" definition

I have a role with the following yaml:

`

[root@ansible playbooks]# head -n 4 roles/upgrade_couchbase/tasks/main.yml

  • hosts: COUCHBASE-cluster-{{ couchbase_environment }}
    serial: 1
    become: yes
    tasks:

`

and a playbook:

`

[root@ansible playbooks]# cat update_couchbase.yml

  • tasks:
  • import_role:
    name: upgrade_couchbase
    vars:
    couchbase_environment: “prod-dr”

`

But when I’m trying to run the playbook, it’s fault on:

`
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

`

What am I doing wrong?

I forgot to mention versions:

ansible = 2.7.0
python version = 2.7.5

Do you have anything written in the task portion? You only showed the task line, but that is also where your head command cuts off. If you don’t have anything written after that, that is most likely your problem. If you do have something written after that, we would need to see what you have written to be able to help further.

You are mixing roles and plays in wrong ways.

play == mapping between hosts and tasks (only place 'hosts: ' can
appear is in a play)
role == collection of tasks/vars and other resources that can be
reused in a play

your role has a hosts: entry, which is incorrect, your play does not
have a hosts: entry ...which is also incorrect

Why does your ‘playbook’ doesn’t have “hosts”?
Why does your ‘role’ have “hosts:”?