Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/elasticache/tasks/main.yml

raw
1 ---
2
3 - name: Integration testing for the elasticache module
4 module_defaults:
5 group/aws:
6 access_key: '{{ aws_access_key }}'
7 secret_key: '{{ aws_secret_key }}'
8 session_token: '{{ security_token | default(omit) }}'
9 region: '{{ aws_region }}'
10 collections:
11 - amazon.aws
12 block:
13 # == Dependency setup ==
14
15 - name: Create VPC to launch Elasticache instances into
16 ec2_vpc_net:
17 name: "{{ vpc_name }}"
18 cidr_block: "{{ vpc_cidr_prefix }}.0.0/16"
19 state: present
20 register: elasticache_vpc
21
22 - name: Create subnet 1 in this VPC to launch Elasticache instances into
23 ec2_vpc_subnet:
24 vpc_id: "{{ elasticache_vpc.vpc.id }}"
25 cidr: "{{ vpc_cidr_prefix }}.1.0/24"
26 state: present
27 register: elasticache_vpc_subnet_1
28
29 - name: Create subnet 2 in this VPC to launch Elasticache instances into
30 ec2_vpc_subnet:
31 vpc_id: "{{ elasticache_vpc.vpc.id }}"
32 cidr: "{{ vpc_cidr_prefix }}.2.0/24"
33 state: present
34 register: elasticache_vpc_subnet_2
35
36 - name: Create Elasticache Subnet Group (grouping two subnets together)
37 elasticache_subnet_group:
38 name: "{{ elasticache_subnet_group_name }}"
39 description: Subnet group grouping together both VPC subnets for Elasticache Test setup
40 subnets:
41 - "{{ elasticache_vpc_subnet_1.subnet.id }}"
42 - "{{ elasticache_vpc_subnet_2.subnet.id }}"
43 state: present
44
45 # == Actual testing of the elasticache module ==
46
47 - name: Create Redis Server on Elasticache in VPC subnets
48 elasticache:
49 name: "{{ elasticache_redis_test_name }}"
50 engine: redis
51 node_type: cache.t3.micro
52 cache_port: "{{ elasticache_redis_port }}"
53 cache_subnet_group: "{{ elasticache_subnet_group_name }}"
54 num_nodes: 1
55 state: present
56 register: elasticache_redis
57
58 - name: Assert that task worked
59 assert:
60 that:
61 - elasticache_redis is changed
62 - elasticache_redis.elasticache.data is defined
63 - elasticache_redis.elasticache.name == elasticache_redis_test_name
64 - elasticache_redis.elasticache.data.CacheSubnetGroupName == elasticache_subnet_group_name
65
66 - name: Add security group for Redis access in Elasticache
67 ec2_security_group:
68 name: "{{ elasticache_redis_sg_name }}"
69 description: Allow access to Elasticache Redis for testing EC module
70 vpc_id: "{{ elasticache_vpc.vpc.id }}"
71 rules:
72 - proto: tcp
73 from_port: "{{ elasticache_redis_port }}"
74 to_port: "{{ elasticache_redis_port }}"
75 cidr_ip: 10.31.0.0/16
76 register: elasticache_redis_sg
77
78 - name: Update Redis Elasticache config with security group (to if changes to existing setup work)
79 elasticache:
80 name: "{{ elasticache_redis.elasticache.name }}"
81 engine: redis
82 node_type: cache.t3.micro
83 num_nodes: 1
84 cache_port: "{{ elasticache_redis_port }}"
85 cache_subnet_group: "{{ elasticache_subnet_group_name }}"
86 security_group_ids: "{{ elasticache_redis_sg.group_id }}"
87 state: present
88 register: elasticache_redis_new
89
90 - name: Assert that task worked
91 assert:
92 that:
93 - elasticache_redis_new is changed
94 - elasticache_redis_new.elasticache.data is defined
95 - elasticache_redis_new.elasticache.data.Engine == "redis"
96 - elasticache_redis_new.elasticache.data.SecurityGroups.0.SecurityGroupId == elasticache_redis_sg.group_id
97
98 - name: Describe all Elasticache clusters
99 elasticache_info: {}
100 register: elasticache_info
101
102 - assert:
103 that:
104 - '"elasticache_clusters" in elasticache_info'
105 - elasticache_info.elasticache_clusters | length >= 1
106
107 - name: Describe Elasticache Redis cluster
108 elasticache_info:
109 name: "{{ elasticache_redis.elasticache.name }}"
110 register: elasticache_info
111
112 - assert:
113 that:
114 - '"elasticache_clusters" in elasticache_info'
115 - elasticache_info.elasticache_clusters | length == 1
116 - '"arn" in elasticache_info.elasticache_clusters[0]'
117 - '"at_rest_encryption_enabled" in elasticache_info.elasticache_clusters[0]'
118 - '"auth_token_enabled" in elasticache_info.elasticache_clusters[0]'
119 - '"auto_minor_version_upgrade" in elasticache_info.elasticache_clusters[0]'
120 - '"cache_cluster_create_time" in elasticache_info.elasticache_clusters[0]'
121 - '"cache_cluster_id" in elasticache_info.elasticache_clusters[0]'
122 - '"cache_cluster_status" in elasticache_info.elasticache_clusters[0]'
123 - '"cache_node_type" in elasticache_info.elasticache_clusters[0]'
124 - '"cache_nodes" in elasticache_info.elasticache_clusters[0]'
125 - '"cache_parameter_group" in elasticache_info.elasticache_clusters[0]'
126 - '"cache_security_groups" in elasticache_info.elasticache_clusters[0]'
127 - '"cache_subnet_group_name" in elasticache_info.elasticache_clusters[0]'
128 - '"client_download_landing_page" in elasticache_info.elasticache_clusters[0]'
129 - '"engine" in elasticache_info.elasticache_clusters[0]'
130 - '"engine_version" in elasticache_info.elasticache_clusters[0]'
131 - '"num_cache_nodes" in elasticache_info.elasticache_clusters[0]'
132 - '"pending_modified_values" in elasticache_info.elasticache_clusters[0]'
133 - '"preferred_availability_zone" in elasticache_info.elasticache_clusters[0]'
134 - '"preferred_maintenance_window" in elasticache_info.elasticache_clusters[0]'
135 - '"security_groups" in elasticache_info.elasticache_clusters[0]'
136 - '"snapshot_retention_limit" in elasticache_info.elasticache_clusters[0]'
137 - '"snapshot_window" in elasticache_info.elasticache_clusters[0]'
138 - '"tags" in elasticache_info.elasticache_clusters[0]'
139 - '"transit_encryption_enabled" in elasticache_info.elasticache_clusters[0]'
140 - elasticache_info.elasticache_clusters[0].arn.startswith("arn:aws")
141 - elasticache_info.elasticache_clusters[0].at_rest_encryption_enabled == False
142 - elasticache_info.elasticache_clusters[0].auth_token_enabled == False
143 - elasticache_info.elasticache_clusters[0].auto_minor_version_upgrade == True
144 - elasticache_info.elasticache_clusters[0].cache_cluster_status == "available"
145 - elasticache_info.elasticache_clusters[0].cache_node_type == "cache.t3.micro"
146 - elasticache_info.elasticache_clusters[0].cache_subnet_group_name == elasticache_subnet_group_name
147 - elasticache_info.elasticache_clusters[0].engine == "redis"
148 - elasticache_info.elasticache_clusters[0].num_cache_nodes == 1
149 - elasticache_info.elasticache_clusters[0].snapshot_retention_limit == 0
150 - elasticache_info.elasticache_clusters[0].transit_encryption_enabled == False
151 - elasticache_info.elasticache_clusters[0].cache_nodes | length == 1
152 - '"cache_node_create_time" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
153 - '"cache_node_id" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
154 - '"cache_node_status" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
155 - '"customer_availability_zone" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
156 - '"endpoint" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
157 - '"parameter_group_status" in elasticache_info.elasticache_clusters[0].cache_nodes[0]'
158 - elasticache_info.elasticache_clusters[0].cache_nodes[0].cache_node_status == "available"
159 - elasticache_info.elasticache_clusters[0].cache_nodes[0].parameter_group_status == "in-sync"
160 - '"address" in elasticache_info.elasticache_clusters[0].cache_nodes[0].endpoint'
161 - '"port" in elasticache_info.elasticache_clusters[0].cache_nodes[0].endpoint'
162 - '"cache_node_ids_to_reboot" in elasticache_info.elasticache_clusters[0].cache_parameter_group'
163 - '"cache_parameter_group_name" in elasticache_info.elasticache_clusters[0].cache_parameter_group'
164 - '"parameter_apply_status" in elasticache_info.elasticache_clusters[0].cache_parameter_group'
165 - elasticache_info.elasticache_clusters[0].cache_parameter_group.cache_node_ids_to_reboot | length == 0
166 - elasticache_info.elasticache_clusters[0].cache_parameter_group.parameter_apply_status == "in-sync"
167 - elasticache_info.elasticache_clusters[0].security_groups | length == 1
168 - '"security_group_id" in elasticache_info.elasticache_clusters[0].security_groups[0]'
169 - '"status" in elasticache_info.elasticache_clusters[0].security_groups[0]'
170 - elasticache_info.elasticache_clusters[0].security_groups[0].security_group_id == elasticache_redis_sg.group_id
171 - elasticache_info.elasticache_clusters[0].security_groups[0].status == "active"
172
173 always:
174
175 # == Cleanup ==
176
177 - name: Make sure test Redis is deleted again from Elasticache
178 elasticache:
179 name: "{{ elasticache_redis_test_name }}"
180 engine: redis
181 state: absent
182
183 - name: Make sure Elasticache Subnet group is deleted again
184 elasticache_subnet_group:
185 name: "{{ elasticache_subnet_group_name }}"
186 state: absent
187
188 - name: Make sure Redis Security Group is deleted again
189 ec2_security_group:
190 name: "{{ elasticache_redis_sg_name }}"
191 state: absent
192
193 - name: Make sure VPC subnet 1 is deleted again
194 ec2_vpc_subnet:
195 vpc_id: "{{ elasticache_vpc.vpc.id }}"
196 cidr: "{{ vpc_cidr_prefix }}.1.0/24"
197 state: absent
198
199 - name: Make sure VPC subnet 2 is deleted again
200 ec2_vpc_subnet:
201 vpc_id: "{{ elasticache_vpc.vpc.id }}"
202 cidr: "{{ vpc_cidr_prefix }}.2.0/24"
203 state: absent
204
205 - name: Make sure VPC is deleted again (only works if subnets were deleted)
206 ec2_vpc_net:
207 name: "{{ vpc_name }}"
208 cidr_block: "{{ vpc_cidr_prefix }}.0.0/16"
209 state: absent