Using nested conditinal blocks in ansible

ansible

I am trying to insert a conditional block inside a conditional block:

- block:
  - postgresql_db: name={{ dbname }} state=absent
  - postgresql_db: name={{ dbname }}
  ...
  - block:
     - get_url: url={{ remote_database_dump }} dest={{ local_database_dump }}
     - command: pg_restore -d {{ dbname }} {{ local_database_dump }}
    when remote_database_dump != ""
  become: true
  become_user: postgres
  become_method: su
  when: db_recreate == "true"

But I get a ERROR! Syntax Error while loading YAML. message. If I remove the when remote_database_dump != "", it works fine.

Is this nesting possible? If yes, how?

Best Answer

Actually, the when remote_database_dump != "" was missing a colon after the when, so the correct line was when: remote_database_dump != "".