Skip to content

Commit b533ed7

Browse files
authored
Split filters into separate files (#14)
* Split filters into separate files * Skip fact gathering on filter tests
1 parent 6ea4b10 commit b533ed7

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2016 Matt Clay <[email protected]>
2+
# GNU General Public License v3.0+ (see LICENSE.md or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
4+
5+
def ec2_az_vpc_route_tables_subnets(zones, subnet):
6+
return [map_zone_to_subnet(z, subnet) for z in zones]
7+
8+
9+
def map_zone_to_subnet(zone, subnet):
10+
position = ord(zone[-1:]) - ord('a')
11+
return subnet % position
12+
13+
14+
class FilterModule(object):
15+
def filters(self):
16+
return dict(
17+
ec2_az_vpc_route_tables_subnets=ec2_az_vpc_route_tables_subnets,
18+
)

plugins/filter/ec2_filters.py renamed to plugins/filter/ec2_az_vpc_subnets.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def ec2_az_vpc_subnets(zones, subnet, name):
1111
) for z in zones]
1212

1313

14-
def ec2_az_vpc_route_tables_subnets(zones, subnet):
15-
return [map_zone_to_subnet(z, subnet) for z in zones]
16-
17-
1814
def map_zone_to_subnet(zone, subnet):
1915
position = ord(zone[-1:]) - ord('a')
2016
return subnet % position
@@ -24,5 +20,4 @@ class FilterModule(object):
2420
def filters(self):
2521
return dict(
2622
ec2_az_vpc_subnets=ec2_az_vpc_subnets,
27-
ec2_az_vpc_route_tables_subnets=ec2_az_vpc_route_tables_subnets
2823
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gather_facts/no
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gather_facts/no
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: Test ec2_az_vpc_route_tables_subnets filter
2+
assert:
3+
that:
4+
- '{{ {"us-east-1a": {}, "us-east-1b": {}} | mattclay.aws.ec2_az_vpc_route_tables_subnets("192.168.%s.0/24") ==
5+
["192.168.0.0/24", "192.168.1.0/24"] }}'
6+
- '{{ {"us-east-1f": {}} | mattclay.aws.ec2_az_vpc_route_tables_subnets("192.168.%s.0/24") ==
7+
["192.168.5.0/24"] }}'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gather_facts/no

tests/integration/targets/filter_ec2_filters/tasks/main.yml renamed to tests/integration/targets/filter_ec2_az_vpc_subnets/tasks/main.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@
55
[{ "az": "us-east-1a", "cidr": "192.168.0.0/24", "resource_tags": {"Name": "Bob"}}] }}'
66
- '{{ {"us-east-1f": {}} | mattclay.aws.ec2_az_vpc_subnets("192.168.%s.0/24", "Bob") ==
77
[{ "az": "us-east-1f", "cidr": "192.168.5.0/24", "resource_tags": {"Name": "Bob"}}] }}'
8-
9-
- name: Test ec2_az_vpc_route_tables_subnets filter
10-
assert:
11-
that:
12-
- '{{ {"us-east-1a": {}, "us-east-1b": {}} | mattclay.aws.ec2_az_vpc_route_tables_subnets("192.168.%s.0/24") ==
13-
["192.168.0.0/24", "192.168.1.0/24"] }}'
14-
- '{{ {"us-east-1f": {}} | mattclay.aws.ec2_az_vpc_route_tables_subnets("192.168.%s.0/24") ==
15-
["192.168.5.0/24"] }}'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gather_facts/no

0 commit comments

Comments
 (0)