# Using variable in "hosts" definition

**URL:** <https://forum.ansible.com/t/using-variable-in-hosts-definition/29274>\
**Category:** Ansible Project\
**Created:** [December 17, 2018, 9:43am UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274 "2018-12-17T09:43:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilya\_Ulis](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@Ilya\_Ulis](https://forum.ansible.com/u/Ilya_Ulis)\
**Post date:** [December 17, 2018, 9:43am UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274/1 "2018-12-17T09:43:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ilya\_Ulis](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@Ilya\_Ulis](https://forum.ansible.com/u/Ilya_Ulis)\
**Post date:** [December 17, 2018, 9:53am UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274/2 "2018-12-17T09:53:54Z")

</div>

I forgot to mention versions:

ansible = 2.7.0  
python version = 2.7.5

---

<div class="post-metadata">

**Author:** ![Eric\_Brewer](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@Eric\_Brewer](https://forum.ansible.com/u/Eric_Brewer)\
**Post date:** [December 17, 2018, 6:48pm UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274/3 "2018-12-17T18:48:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 18, 2018, 5:30pm UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274/4 "2018-12-18T17:30:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [December 19, 2018, 1:47am UTC](https://forum.ansible.com/t/using-variable-in-hosts-definition/29274/5 "2018-12-19T01:47:14Z")

</div>

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