Ansible Omit filter behavior issue

Hi,

I am trying to build a role which will help us to create new security groups on AWS based on a dictionary. But I have an issue with one to enable the rules parsing caused by a conflict between 2 args that are mutually exclusive.

Imagine the following lines:

rules:

cidr_ip: “{{ item.1.cidr_ip | default(omit) }}”
group_id: “{{ item.1.group_id | default(omit) }}”

I can only have one or another, but not both defined. I though that ‘omit’ filter would do the job, removing the arg from the rules dictionary, but it is not working. The AWS module trigger this failure:

// ec2_group.py

if ‘group_id’ in rule and ‘cidr_ip’ in rule:
module.fail_json(msg=‘Specify group_id OR cidr_ip, not both’)

Is there anyway that I can solve this issue? Or is this a bug?

Ansible version: 2.2.2.0

// Anderson