Conditional upon variable

I tried to:

command: /usr/sbin/setsebool -P httpd_can_network_connect_db 1
when: “{{rc_db_host}}” = “localhost”

Ansible exploded in rage. I’ve never sent his much red text, even from python errors :slight_smile: I tried with quotes, without, ‘=’, ‘==’… It looks like there’s duplication in the error message, too:

ERROR: Syntax Error while loading YAML script, roundcube.yml
Note: The error may actually appear before this position: line 129, column 28

command: /usr/sbin/setsebool -P httpd_can_network_connect_db 1
when: “{{rc_db_host}}” == “localhost”
^
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:

foo: “bad” “wolf”

Could be written as:

foo: ‘“bad” “wolf”’

We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

with_items:

  • {{ foo }}

Should be written as:

with_items:

  • “{{ foo }}”

We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:

foo: “bad” “wolf”

Could be written as:

foo: ‘“bad” “wolf”’

Try something like this:

    command: /usr/sbin/setsebool -P httpd_can_network_connect_db 1
    when: rc_db_host == "localhost"

You don't need to use templating in the when clauses.

Thanks!!!