# "Using bare variables is deprecated." but the docs are showing me to use that syntax.?

**URL:** <https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [May 11, 2016, 9:55am UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405 "2016-05-11T09:55:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [May 11, 2016, 9:55am UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405/1 "2016-05-11T09:55:52Z")

</div>

Hi List,

I’ve always been following along with the examples here:  
[http://docs.ansible.com/ansible/playbooks\_conditionals.html#the-when-statement](http://docs.ansible.com/ansible/playbooks_conditionals.html#the-when-statement)

for instance:

```auto

- name: Disable requiretty
lineinfile:
dest: /etc/sudoers
regexp: "Defaults requiretty"
line: "# Defaults requiretty"
when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "7"

```

But when I run that with Ansible \> 2.0 it gives me a deprecation message:

```auto

[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{ansible_os_family}}').
This feature will be removed in a future release.

```

When I change the code to this:

```auto

- name: Disable requiretty
lineinfile:
dest: /etc/sudoers
regexp: "Defaults requiretty"
line: "# Defaults requiretty"
when: "{{ ansible_os_family }} == 'RedHat' and {{ ansible_distribution_major_version }} == '7'"

```

I get the error:

```auto
fatal: [10.20.113.218]: FAILED! => {"failed": true, "msg": "The conditional check '{{ ansible_os_family }} == 'RedHat' and {{ ansible_distribution_major_version }} == '7'' failed. The error was: error while evaluating conditional ({{ ansible_os_family }} == 'RedHat' and {{ ansible_distribution_major_version }} == '7'): 'Debian' is undefined\n\nThe error appears to have been in '/home/mark/Documents/persgroep-aws/roles/vnucommon/tasks/main.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Disable requiretty\n ^ here\n"}

```

Am I missing something here?

Thanks,  
Mark Maas

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 11, 2016, 2:30pm UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405/2 "2016-05-11T14:30:39Z")

</div>

Are you sure that this message is because of the when statement and not from other places you have used a variable?

According to Brian Coca in this post {{ and }} is implied in when and should not be used.  
[https://groups.google.com/forum/#!msg/ansible-project/1DyCROTgMF0/6siUigwuAQAJ](https://groups.google.com/forum/#!msg/ansible-project/1DyCROTgMF0/6siUigwuAQAJ)

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [May 12, 2016, 6:06am UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405/3 "2016-05-12T06:06:38Z")

</div>

> > ```auto
> > - name: Disable requiretty
> > lineinfile:
> > dest: /etc/sudoers
> > regexp: "Defaults requiretty"
> > line: "# Defaults requiretty"
> > when: ansible_os_family == "RedHat" and
> > ansible_distribution_major_version == "7"
> > 
> > ```
> > 
> > But when I run that with Ansible \> 2.0 it gives me a deprecation message:
> > 
> > ```auto
> > [DEPRECATION WARNING]: Using bare variables is deprecated. Update your
> > playbooks so that the environment value uses the full variable syntax
> > ('{{ansible_os_family}}').
> > This feature will be removed in a future release.
> > 
> > ```
> 
> Are you sure that this message is because of the when statement and not  
> from other places you have used a variable?

Yes, I’ve seem to have been able to fix it like so:

```auto

- name: Disable requiretty
lineinfile:
dest: /etc/sudoers
regexp: "Defaults requiretty"
line: "# Defaults requiretty"
when: "'{{ ansible_os_family }}' == 'RedHat' and '{{ ansible_distribution_major_version }}' == '7'"

```

Apparantly one needs to use, double quotes, single quotes and accolades to make ansible 2.0 happy.

This should actually be fixed in the docs, those pages are simply wrong at the moment.

> According to Brian Coca in this post {{ and }} is implied in when and  
> should not be used.  
> [https://groups.google.com/forum/#!msg/ansible-project/1DyCROTgMF0/6siUigwuAQAJ](https://groups.google.com/forum/#!msg/ansible-project/1DyCROTgMF0/6siUigwuAQAJ)

Now I’m lost, when I leave those out, ansible cries foul and throws me a deprectation warning.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 12, 2016, 2:10pm UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405/4 "2016-05-12T14:10:41Z")

</div>

I tested this task with 2.0.2.0 and doesn't get any deprecation messages:

&nbsp;&nbsp;&nbsp;- name: Create directories  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: dest=/tmp/foo state=directory  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_os\_family == "Debian" and ansible\_distribution\_major\_version == "15"

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 12, 2016, 2:14pm UTC](https://forum.ansible.com/t/using-bare-variables-is-deprecated-but-the-docs-are-showing-me-to-use-that-syntax/21405/5 "2016-05-12T14:14:36Z")

</div>

I’ve ended up with 2 simple rules on {{}}

1. moustaches don’t stack!! {{ var1[{{var2}}] }} \<= wrong, just {{var1[var2]}}
2. always use moustaches except when when:. All conditionals already have implied {{ }} so you would be violating rule #1, which CAN work but sometimes gives you unexpected results.

The error you are getting should ONLY happen when using a var w/o {{ }} in a with\_ clause.
