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

8,161 views
Skip to first unread message

Giovanni Tirloni

unread,
Apr 28, 2015, 8:43:21 PM4/28/15
to ansible...@googlegroups.com
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

Giovanni Tirloni

unread,
Apr 29, 2015, 9:43:06 AM4/29/15
to ansible...@googlegroups.com
On Tue, 28 Apr 2015 17:43 -0700, Giovanni Tirloni <g...@gtirloni.com>
wrote:
> 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'

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
command: "/usr/sbin/semanage port -a -t ssh_port_t -p tcp 8888"
when: ansible_selinux.status == "enabled"

Giovanni
Reply all
Reply to author
Forward
0 new messages