ignore -has no attribute

25 views
Skip to first unread message

Jegan A

unread,
Jan 23, 2020, 5:18:55 AM1/23/20
to Ansible Project
Hello Team,

   I am parsing register value using debug and using when condition to print particular matching value. While doing that am getting below error. some of the register value doesn't have "volume_attachments" variable due to that the when condition is failing. I want to ignore this error how can I do it. Could you please help me on this. Thanks in advance.
  
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'item.volume_attachments | length == 0' failed. The error was: error while evaluating conditional (item.volume_attachments | length == 0): 'dict object' has no attribute 'volume_attachments'\n\nThe error appears to be in '/var/lib/home/s': line 33, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - debug:\n      ^ here\n"}


Regards,
Jegan A

Martin Krizek

unread,
Jan 23, 2020, 5:58:57 AM1/23/20
to ansible...@googlegroups.com
Use "default" filter:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#defaulting-undefined-variables

Example:
- hosts: localhost
gather_facts: no
vars:
d:
key: value
tasks:
- debug:
msg: "{{ d.missing_attr | default('default_value') }}"
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b7353ab1-5a43-4d6d-a510-21d3dba61e1d%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages