Skip to content

Commit 10789d8

Browse files
committedApr 3, 2020
Replace ec2_ami_find with ec2_ami_facts
1 parent 5c9ad97 commit 10789d8

File tree

11 files changed

+42
-46
lines changed

11 files changed

+42
-46
lines changed
 

‎requirements-python.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# highest version provisioning runs fully on
2-
ansible>=2.7,<2.8
1+
# DO NOT upgrade to >=2.9.3 until
2+
# https://github.com/ansible/ansible/issues/66641
3+
ansible==2.9.2
34

45
# needed for inventory and aws modules
56
boto3
@@ -21,4 +22,4 @@ docker-py
2122
awscli
2223

2324
# required for awscli
24-
PyYAML<5.3
25+
PyYAML<5.3

‎roles/cs.aws-create-ami/tasks/main.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
register: ami_output
1616

1717
- name: Wait until AMI is accessible
18-
ec2_ami_find:
18+
ec2_ami_info:
1919
region: "{{ aws_region }}"
2020
owner: self
21-
sort: creationDate
22-
sort_order: descending
23-
no_result_action: fail
24-
ami_tags: "{{ aws_tags_base | combine(ami_tags) }}"
25-
register: ami_found
26-
until: ami_found.results is defined and ami_found.results[0].ami_id == ami_output.image_id and ami_found.results[0].state == "available"
21+
filters: "{{ aws_tags_base | prefix_keys('tag:') | combine(ami_facts_tag_filters) }}"
22+
vars:
23+
ami_facts_tag_filters: "{{ ami_tags | prefix_keys('tag:') }}"
24+
register: ami_facts
25+
until: "ami_facts.images is defined and ami_facts.images|length > 0"
2726
retries: 60
2827
delay: 5
2928
when: ami_output is changed
30-
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- role: cs.ansible-plugins

‎roles/cs.aws-ec2-cleanup/tasks/main.yml

+8-12
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@
3232
msg: "Keeping {{ _aws_ec2_cleanup_ami_ids_to_keep | count }} AMIs: {{ _aws_ec2_cleanup_ami_ids_to_keep | join(', ') }}"
3333

3434
- name: Get list of App AMIs
35-
ec2_ami_find:
35+
ec2_ami_info:
3636
region: "{{ aws_region }}"
3737
owner: self
38-
sort: creationDate
39-
sort_order: descending
40-
ami_tags:
41-
"Role": "app"
42-
"Project": "{{ mageops_project }}"
43-
"Environment": "{{ mageops_environment }}"
38+
filters: "{{ aws_tags_base | prefix_keys('tag:') | combine(aws_tags_role_app_filter) }}"
39+
vars:
40+
aws_tags_role_app_filter: "{{ aws_tags_role_app | prefix_keys('tag:') }}"
4441
register: _aws_ec2_cleanup_env_amis
4542

4643
- name: "Remove Launch Configurations not longer required"
@@ -56,9 +53,8 @@
5653
region: "{{ aws_region }}"
5754
state: absent
5855
delete_snapshot: yes
59-
image_id: "{{ item.ami_id }}"
60-
with_items: "{{ _aws_ec2_cleanup_env_amis.results }}"
56+
image_id: "{{ item.image_id }}"
57+
with_items: "{{ _aws_ec2_cleanup_env_amis.images }}"
6158
when:
62-
- not item | skipped
63-
- item.ami_id not in _aws_ec2_cleanup_ami_ids_to_keep
64-
59+
- item is not skipped
60+
- item.image_id not in _aws_ec2_cleanup_ami_ids_to_keep

‎roles/cs.aws-node-facts/tasks/main.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- name: Get EC2 instance information for nodes
2-
ec2_instance_facts:
2+
ec2_instance_info:
33
region: "{{ aws_region }}"
44
filters: "{{ aws_node_facts_base_filters | combine(aws_node_facts_base_tags | combine(node.tags) | prefix_keys('tag:')) }}"
55
loop:
@@ -72,4 +72,3 @@
7272
set_fact:
7373
mageops_redis_sessions_host: "{{ aws_nodes_info.redis.private_ip_address }}"
7474
when: not mageops_redis_sessions_host | default(false, true) and aws_nodes_info.redis
75-
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
- name: Find EC2 instances to be processed
2-
ec2_instance_facts:
2+
ec2_instance_info:
33
region: "{{ aws_region }}"
44
filters: "{{ node_state_instance_filters | combine(node_state_instance_tags | prefix_keys('tag:')) }}"
5-
register: node_state_ec2_instance_facts
5+
register: node_state_ec2_instance_info
66

77
- name: Enforce target state instances found
88
ec2:
99
region: "{{ aws_region }}"
1010
state: "{{ node_state_target }}"
11-
instance_ids: "{{ node_state_ec2_instance_facts.instances | map(attribute='instance_id') | list }}"
11+
instance_ids: "{{ node_state_ec2_instance_info.instances | map(attribute='instance_id') | list }}"
1212
wait: yes
13-
when: node_state_ec2_instance_facts.instances | length > 0
13+
when: node_state_ec2_instance_info.instances | length > 0

‎roles/cs.varnish/tasks/000-facts.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
- name: Get VPC IP addresses of backend app instances
44
delegate_to: localhost
55
become: no
6-
ec2_instance_facts:
6+
ec2_instance_info:
77
region: "{{ aws_region }}"
88
filters: "{{ varnish_backend_instances_filter_base | combine(varnish_backend_instances_aws_tags | prefix_keys('tag:')) }}"
9-
register: _varnish_backends_ec2_instance_facts
9+
register: _varnish_backends_ec2_instance_info
1010

1111
- name: Set Varnish backend instances if any are running (AWS)
1212
set_fact:
13-
varnish_backend_instances_app: "{{ _varnish_backends_ec2_instance_facts.instances }}"
14-
when: _varnish_backends_ec2_instance_facts.instances | length > 0
13+
varnish_backend_instances_app: "{{ _varnish_backends_ec2_instance_info.instances }}"
14+
when: _varnish_backends_ec2_instance_info.instances | length > 0
1515
when: varnish_standalone and aws_use
1616

1717
- name: Check if throttling shall be enabled
1818
set_fact:
19-
varnish_throttling_enabled: "{{ (varnish_standalone and varnish_throttling and varnish_throttling_rules | length > 0)|bool }}"
19+
varnish_throttling_enabled: "{{ (varnish_standalone and varnish_throttling and varnish_throttling_rules | length > 0)|bool }}"

‎site.maintenance.aws-remove-all.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
- name: Remove other EC2 Servers
3838
block:
3939
- name: Get list of EC2 instances
40-
ec2_instance_facts:
40+
ec2_instance_info:
4141
region: "{{ aws_region }}"
4242
filters:
4343
"vpc-id": "{{ _aws_vpc_id }}"

‎site.maintenance.aws-start.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
when: start_ec2
1111
block:
1212
- name: Get list of EC2 instances
13-
ec2_instance_facts:
13+
ec2_instance_info:
1414
region: "{{ aws_region }}"
1515
filters:
1616
"vpc-id": "{{ aws_vpc_id }}"
17-
register: start_ec2_instance_facts
17+
register: start_ec2_instance_info
1818

1919
- name: Start instances
2020
ec2:
@@ -24,7 +24,7 @@
2424
wait_timeout: 600
2525
wait: yes
2626
vars:
27-
start_ec2_instance_ids: "{{ start_ec2_instance_facts | json_query('instances[].instance_id') }}"
27+
start_ec2_instance_ids: "{{ start_ec2_instance_info | json_query('instances[].instance_id') }}"
2828

2929
- name: Scale up App Node ASGs
3030
when: start_asg
@@ -48,7 +48,7 @@
4848
with_items: "{{ start_asgs }}"
4949
vars:
5050
start_asgs: "{{ start_asg_facts | json_query('results[].{ name: auto_scaling_group_name, lc: launch_configuration_name}') }}"
51-
51+
5252
- name: Scale up Extra App Node ASGs
5353
when: start_asg and (aws_extra_app_asg_enable or magento_aws_ondemand_import_instance_enable)
5454
block:
@@ -70,7 +70,7 @@
7070
wait_timeout: 600
7171
with_items: "{{ start_asgs }}"
7272
vars:
73-
start_asgs: "{{ start_asg_facts | json_query('results[].{ name: auto_scaling_group_name, lc: launch_configuration_name}') }}"
73+
start_asgs: "{{ start_asg_facts | json_query('results[].{ name: auto_scaling_group_name, lc: launch_configuration_name}') }}"
7474

7575
vars:
7676
start: yes

‎site.maintenance.aws-stop.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
with_items: "{{ stop_asgs }}"
2828
vars:
2929
stop_asgs: "{{ stop_asg_facts | json_query('results[].{ name: auto_scaling_group_name, lc: launch_configuration_name}') }}"
30-
30+
3131
- name: Stop standalone EC2 instances
3232
when: stop_ec2
3333
block:
3434
- name: Get list of EC2 instances
35-
ec2_instance_facts:
35+
ec2_instance_info:
3636
region: "{{ aws_region }}"
3737
filters:
3838
"vpc-id": "{{ aws_vpc_id }}"
39-
register: stop_ec2_instance_facts
39+
register: stop_ec2_instance_info
4040

4141
- name: Stop instances
4242
ec2:
@@ -45,7 +45,7 @@
4545
state: stopped
4646
wait: no
4747
vars:
48-
stop_ec2_instance_ids: "{{ stop_ec2_instance_facts | json_query('instances[].instance_id') }}"
48+
stop_ec2_instance_ids: "{{ stop_ec2_instance_info | json_query('instances[].instance_id') }}"
4949
vars:
5050
stop: yes
5151
stop_ec2: "{{ stop }}"

‎site.maintenance.blackfire.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
become: no
44
tasks:
55
- name: Get list of EC2 instances
6-
ec2_instance_facts:
6+
ec2_instance_info:
77
region: "{{ aws_region }}"
88
filters:
99
"tag:Role": "app"
@@ -56,4 +56,4 @@
5656
- vars/aws/env.yml
5757
vars:
5858
blackfire_urls:
59-
- "{{ magento_base_url }}"
59+
- "{{ magento_base_url }}"

0 commit comments

Comments
 (0)
Please sign in to comment.