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

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

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