# template error while templating string: expected token ':', got 'string'

**URL:** <https://forum.ansible.com/t/template-error-while-templating-string-expected-token-got-string/18121>\
**Category:** Ansible Project\
**Tags:** ansible-lint\
**Created:** [April 29, 2015, 12:43am UTC](https://forum.ansible.com/t/template-error-while-templating-string-expected-token-got-string/18121 "2015-04-29T00:43:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [April 29, 2015, 12:43am UTC](https://forum.ansible.com/t/template-error-while-templating-string-expected-token-got-string/18121/1 "2015-04-29T00:43:21Z")

</div>

Hi,

I’m getting the following error when applying a task from a role:

TASK: [debug var=ansible\_selinux] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [prd-node01] =\> {  
“var”: {  
“ansible\_selinux”: {  
“status”: “disabled”  
}  
}  
}

TASK: [Update SELinux configuration] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [prd-node01] =\> template error while templating string: expected token ‘:’, got ‘string’

This is the task from role/tasks/main.yml:

- name: Update SELinux configuration  
command: “/usr/sbin/semanage port -a -t ssh\_port\_t -p tcp 8888”  
when: ansible\_selinux

I’ve tried moving it up and down in the main.yml file, thinking it might be a quote somewhere (even down syntax-check and ansible-lint say everything is fine), no luck.

The curious thing is that, if I create a playbook with just this one task, everything works as expected (task is skipped because ansible\_selinux is ‘false’).

TASK: [Update SELinux configuration] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [localhost]

Any ideas?

Giovanni

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [April 29, 2015, 1:42pm UTC](https://forum.ansible.com/t/template-error-while-templating-string-expected-token-got-string/18121/2 "2015-04-29T13:42:58Z")

</div>

For some reason I assumed "ansible\_selinux" was a boolean.

Since it's a dictionary, and the "status" key is a string, I had to  
checked it as follows:

- name: Update SELinux configuration  
&nbsp;&nbsp;command: "/usr/sbin/semanage port -a -t ssh\_port\_t -p tcp 8888"  
&nbsp;&nbsp;when: ansible\_selinux.status == "enabled"

Giovanni
