Skip to content

Commit

Permalink
Fix failures in AWS provision/teardown
Browse files Browse the repository at this point in the history
Fixes CentOS-PaaS-SIG#495 - linchpin destroy fails for AWS
Fixes CentOS-PaaS-SIG#497 - linchpin up AWS target fails when using CREDS_PATH
  • Loading branch information
Clint Savage committed Mar 29, 2018
1 parent ae52244 commit 5f252b5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
8 changes: 4 additions & 4 deletions docs/source/examples/workspace/topologies/aws-ec2-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ resource_groups:
resource_group_type: "aws"
resource_definitions:
- name: demo-day
flavor: m1.small
flavor: t2.micro
role: aws_ec2
region: us-east-1
image: ami-984189e2
region: us-west-2
image: ami-a042f4d8
count: 1
credentials:
filename: aws.key
filename: aws.credentials
profile: default
31 changes: 4 additions & 27 deletions linchpin/provision/roles/aws/tasks/teardown_aws_ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,18 @@
with_together:
- "{{ auth_var['aws_access_key_id'] | default(omit) }}"
- "{{ auth_var['aws_secret_access_key'] | default(omit) }}"
- "{{ tp_out.instance_ids | join(',') }}"
- "{{ tp_out['id'] }}"
- "{{ res_def['region'] }}"
- "{{ tp_out['instances'][0]['tags']['resource_group_name'] }}"
- "{{ tp_out['tags']['resource_group_name'] }}"
- "{{ res_grp_name }}"
- "{{ res_def['role'] }}"
- "{{ async }}"
loop_control:
loop_var: res_def_item
register: output_item

- name: "Async:: Teardown AWS_EC2 Resource"
ec2:
aws_access_key: "{{ res_def_item.0 }}"
aws_secret_key: "{{ res_def_item.1 }}"
instance_ids: "{{ res_def_item.2 }}"
state: 'absent'
region: "{{ res_def_item.3 }}"
wait: yes
when: res_def_item.4 == res_def_item.5 and res_def_item.6 == "aws_ec2" and res_def_item.7 == true
with_together:
- "{{ auth_var['aws_access_key_id'] | default(omit) }}"
- "{{ auth_var['aws_secret_access_key'] | default(omit) }}"
- "{{ tp_out.instance_ids | join(',') }}"
- "{{ res_def['region'] }}"
- "{{ tp_out['instances'][0]['tags']['resource_group_name'] }}"
- "{{ res_grp_name }}"
- "{{ res_def['role'] }}"
- "{{ async }}"
loop_control:
loop_var: res_def_item
async: "{{ async_timeout }}"
poll: 0
register: output_item
no_log: true

# following tasks saves the async job details
- name: "Async:: save the job id"
- name: "Save the job id"
set_fact:
topology_outputs_aws_ec2: "{{ topology_outputs_aws_ec2 + [output_item] }}"
2 changes: 1 addition & 1 deletion linchpin/provision/roles/aws/tasks/teardown_res_defs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
when: res_item.0['role'] == "aws_ec2"
with_nested:
- "{{ res_grp['res_defs'] | default(res_grp['resource_definitions']) }}"
- "{{ topo_output['output']['content']['aws_ec2_res'] }}"
- "{{ topo_output['instance_ids'] }}"
- ["{{ res_grp['resource_group_name'] }}"]
loop_control:
loop_var: res_item
Expand Down
38 changes: 19 additions & 19 deletions linchpin/provision/roles/aws/tasks/teardown_resource_group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
auth_driver:
filename: "{{ res_grp['credentials']['filename'] }}"
cred_type: "aws"
cred_path: "{{ creds_path }}"
cred_path: "{{ creds_path | default(default_credentials_path) }}"
driver: "file"
register: auth_var
ignore_errors: true
Expand All @@ -19,21 +19,7 @@
auth_var: "{{ auth_var['output'][cred_profile] | default('') }}"
ignore_errors: true
when: auth_var is defined

- name: "Get topology output data from RunDb"
rundb:
conn_str: "{{ rundb_conn }}"
operation: get
table: "{{ target }}"
key: "outputs"
run_id: "{{ orig_run_id }}"
register: topo_output
when: not generate_resources

- name: "set topo_output_resources fact"
set_fact:
topo_output_resources: "{{ topo_output.output[0]['resources'] }}"
when: not generate_resources
no_log: true

- name: "Get topology output data from resources file"
output_parser:
Expand All @@ -44,21 +30,35 @@

- name: "set topo_output_resources fact"
set_fact:
topo_output_resources: "{{ topo_output.output['content'] }}"
topo_output_resources: "{{ topo_output.output['content']['aws_ec2_res'][0] }}"
when: generate_resources


# patch for role to type translation
- name: "Add attribute role to res_grp resource_definitions"
set_fact:
resource_definitions: "{{ res_grp['res_defs'] | default(res_grp['resource_definitions']) | duplicateattr('role', 'role') }}"

- name: "Get topology output data from RunDb"
rundb:
conn_str: "{{ rundb_conn }}"
operation: get
table: "{{ target }}"
key: "outputs"
run_id: "{{ orig_run_id }}"
register: topo_output_rundb
when: not generate_resources

- name: "set topo_output_resources fact rundb"
set_fact:
topo_output_resources: "{{ topo_output_rundb.output[0]['resources'][0] }}"
when: not generate_resources

- name: "teardown of ec2 resource definitions of current group"
include: teardown_aws_ec2.yml res_def={{ res_item.0 }} tp_out={{ res_item.1 }} res_grp_name={{ res_item.2 }}
when: res_item.0['role'] == "aws_ec2"
with_nested:
- "{{ resource_definitions }}"
- "{{ topo_output_resources['aws_ec2_res'] }}"
- "{{ topo_output_resources['instances'] }}"
- ["{{ res_grp['resource_group_name'] }}"]
loop_control:
loop_var: res_item
Expand Down

0 comments on commit 5f252b5

Please sign in to comment.