-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inventory aws_ec2 - add support for AND logic on exclude and include
filters
- Loading branch information
Showing
11 changed files
with
208 additions
and
27 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/1361-inventory_aws_ec2-support-and-logic-for-filters.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- inventory aws ec2 - support AND logic when using exclude and/or include filters (https://github.com/ansible-collections/amazon.aws/issues/1354). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/integration/targets/inventory_aws_ec2/playbooks/manage_ec2_instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
- hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: no | ||
gather_facts: false | ||
|
||
collections: | ||
- amazon.aws | ||
|
21 changes: 21 additions & 0 deletions
21
...rgets/inventory_aws_ec2/playbooks/test_populating_inventory_with_AND_logic_on_filters.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: false | ||
environment: "{{ ansible_test.environment }}" | ||
tasks: | ||
|
||
- meta: refresh_inventory | ||
|
||
- name: "Ensure we've got a hostvars entry for the new host {{ item }}" | ||
assert: | ||
that: | ||
- item in hostvars | ||
with_items: "{{ test_inventory_hosts }}" | ||
when: test_inventory_hosts | default([]) | length > 0 | ||
|
||
- name: "Ensure we've got no hosts from inventory" | ||
assert: | ||
that: | ||
- hostvars.keys() | list | length == 0 | ||
when: test_inventory_hosts | default([]) | length == 0 |
8 changes: 8 additions & 0 deletions
8
tests/integration/targets/inventory_aws_ec2/playbooks/vars/filters_case1.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
test_inventory_hosts: | ||
- "{{ resource_prefix }}" | ||
test_include_filters: | ||
- tag-key: resource_prefix | ||
test_exclude_filters: | ||
- tag-key: resource_prefix | ||
- tag-key: this_tag_does_not_exist |
5 changes: 5 additions & 0 deletions
5
tests/integration/targets/inventory_aws_ec2/playbooks/vars/filters_case2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
test_inventory_hosts: [] | ||
test_exclude_filters: | ||
- tag-key: resource_prefix | ||
- "tag:Name": "{{ resource_prefix }}" |
6 changes: 6 additions & 0 deletions
6
tests/integration/targets/inventory_aws_ec2/playbooks/vars/filters_case3.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
test_inventory_hosts: | ||
- '{{ resource_prefix }}' | ||
test_exclude_filters: | ||
- tag-key: resource_prefix | ||
- tag-key: this_tag_does_not_exist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...inventory_aws_ec2/templates/inventory_with_include_exclude_filters_and_apply_logic.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
plugin: amazon.aws.aws_ec2 | ||
aws_access_key_id: '{{ aws_access_key }}' | ||
aws_secret_access_key: '{{ aws_secret_key }}' | ||
{% if security_token | default(false) %} | ||
aws_security_token: '{{ security_token }}' | ||
{% endif %} | ||
regions: | ||
- '{{ aws_region }}' | ||
filters: | ||
tag:Name: | ||
- {{ resource_prefix }} | ||
include_filters: {{ test_include_filters | default([]) }} | ||
exclude_filters: {{ test_exclude_filters | default([]) }} | ||
hostnames: | ||
- tag:Name | ||
apply_and_logic_on_include_filters: true | ||
apply_and_logic_on_exclude_filters: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters