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?

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.