Conditionals based on empty JSON dict

Hello list,

I’m trying to automate an API call that adds an ‘A’ record to the linode DNS service. The relevant playbook snippet is:

Not tried, but wondering if you could use

  • name: work out if create failed
    set_fact:
    create_a_record_failed: true
    when: linode_api_error.ERRORARRAY|length > 0

to detect if you need to fail, then you can retrieve the error message in a separate step.

  • fail: msg=“Setting DNS entry failed with error ‘{{ linode_api_error.ERRORARRAY.0.ERRORMESSAGE }}’”
    when:create_a_record_failed|default(false)

(I think default(false) would get around the problem that you haven’t necessarily defined create_a_record_failed if there is no error.