How to handle item not in list in ansible variable?
use the condition

- when: variable is defined
  run_module_when_defined:


or 

- name:
  block:
    - task1
    - task2
  when: variable is defined