You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
include_filters is matching on ALL hosts when I expect it to match 0 hosts.
I think what is happening is that filters is the initial filter that is being applied and then include_filters are being applied to that set of matching hosts. If you don't specify ANY filters then it's equivalent to True as the initial filter. Then, when include_filters gets applied you get something like True || include_filter_1 || include_filter_2. Effectively, the include_filters become a NOOP if filters is not specified. I confirmed this suspicion with some pdb in the code.
include_filters = [self.get_option('filters')] + self.get_option('include_filters') <-- in my debugging this is [{}, {'key-name': 'jenkins'}]. Notice the first {}, when the filter list is passed to ansible_dict_to_boto3_filter_list(filter) the empty dict is equivalent to True.
#456 I have a potential fix here, but I feel like it may not take into account the exclude_filters feature.
do not include {} boto filter by default
Depends-On: #480
When no filter: specified, do not include an empty dict in the list of
boto filters because it effectively matches any host.
Closes: #457Closes: #452
ISSUE TYPE
Bugfix Pull Request
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
abikouo
pushed a commit
to abikouo/amazon.aws
that referenced
this issue
Oct 24, 2023
Summary
include_filters
is matching on ALL hosts when I expect it to match 0 hosts.I think what is happening is that
filters
is the initial filter that is being applied and theninclude_filters
are being applied to that set of matching hosts. If you don't specify ANYfilters
then it's equivalent toTrue
as the initial filter. Then, wheninclude_filters
gets applied you get something likeTrue || include_filter_1 || include_filter_2
. Effectively, theinclude_filters
become a NOOP iffilters
is not specified. I confirmed this suspicion with somepdb
in the code.amazon.aws/plugins/inventory/aws_ec2.py
Line 712 in 5876c14
include_filters = [self.get_option('filters')] + self.get_option('include_filters')
<-- in my debugging this is[{}, {'key-name': 'jenkins'}]
. Notice the first{}
, when the filter list is passed toansible_dict_to_boto3_filter_list(filter)
the empty dict is equivalent toTrue
.#456 I have a potential fix here, but I feel like it may not take into account the
exclude_filters
feature.Issue Type
Bug Report
Component Name
aws_ec2
Ansible Version
Collection Versions
AWS SDK versions
Configuration
$ ansible-config dump --only-changed
OS / Environment
CentOS Linux release 8.4.2105
Steps to Reproduce
ansible-inventory -i aws_ec2.yml --list
filters:
feature.include_filters
does NOT match anything in your EC2 infrastructure.Expected Results
I expected 0 hosts to be returned because I assumed that at least 1 filter in the
include_filters
list had to match.Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: