1

I'm currently porting my Ansible playbooks from version 2.1 to 2.7. Ansible now prints a warning if I use jinja templating delmiters such as {{ .. }} in a when clause.

[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}

I had no problems to change it on simple conditionals statements, but I wonder how to fix this one:

- shell: pg_lsclusters -h | awk '{print $2 " " $6}'
  register: postgresql_lsclusters
  changed_when: false
  check_mode: no

- fail: 
    msg="test"
  when: postgresql_lsclusters.stdout.find("{{ postgresql_cluster }} {{ postgresql_data_dir }}/{{ postgresql_version }}/{{ postgresql_cluster }}") == -1

I tried to replace the when statement with the following, without success:

when: postgresql_lsclusters.stdout.find(postgresql_cluster ~ ' ' ~ postgresql_data_dir ~ '/' ~ postgresql_version ~ '/' ~ postgresql_cluster") == -1`
Francis
  • 381
  • 2
  • 6
  • 17
  • I see unbalanced quotes in your example... – Konstantin Suvorov Nov 15 '18 at 18:44
  • Arg, it was just an pebkac error. Sorry for the noise! – Francis Nov 15 '18 at 18:55
  • What error do you get when you use that `when:` with the concat (~) operator? What do you get if you do a `- debug\nmsg: "{{postgresql_cluster ~ ' ' ~ postgresql_data_dir ~ '/' ~ postgresql_version ~ '/' ~ postgresql_cluster"}}"` ? Without knowing more about the contents of your variables and so on, it is hard to troubleshoot, this so my suggestion is to use `- debug` to get your expression right. – Zoredache Nov 15 '18 at 19:33
  • The problem was just the unbalanced quotes. – Francis Nov 16 '18 at 16:31

1 Answers1

0

Something like this?

- name: PG cluster find
  vars:
    big_pg_var: "{{ postgresql_cluster }} {{ postgresql_data_dir }}/{{ postgresql_version }}/{{ postgresql_cluster }}"
  fail:
    msg="test"
  when: postgresql_lsclusters.stdout.find(big_pg_var) == -1
don Rumata
  • 103
  • 5