Skip to content

Commit 320ac9c

Browse files
fix output
1 parent 15f55c3 commit 320ac9c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

site.maintenance.find-untagged.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- "stopping"
1010
_ec2_ebs_list_review: []
1111
_ec2_untagged_list: []
12+
_ec2_list_to_review :
1213
roles:
1314
- role: cs.aws-rds-facts
1415
tasks:
@@ -30,7 +31,7 @@
3031

3132
- name: Generate list EC2 to review
3233
set_fact:
33-
_ec2_untagged_list: "{{ _ec2_untagged_list + [{ 'id' : item.instance_id, 'name' : item.tags.Name }] }}"
34+
_ec2_untagged_list: "{{ _ec2_untagged_list + [{ 'id' : item.instance_id, 'name' : item.tags.Name | default('') }] }}"
3435
when: item.instance_id not in aws_ec2_whitelist
3536
with_items: "{{ _ec2_list_all.instances | difference(_ec2_list_mageops.instances) }}"
3637

@@ -46,14 +47,18 @@
4647
_ec2_ebs_list_review: "{{ _ec2_ebs_list_review + [item.id] }}"
4748
with_items: "{{ _ec2_ebs_list.volumes }}"
4849

49-
- name: Set _ec2_list_review
50+
- name : debug
51+
debug:
52+
var: _ec2_untagged_list
53+
54+
- name: Generate string to end output
5055
set_fact:
51-
_ec2_list_review: "{{ _ec2_list_review | default() + 'ID : ' + item.id + ' Name : ' + item.name | default() '\n' }}"
56+
_ec2_list_to_review: "{{ (_ec2_list_to_review) }} ID : {{ item.id }} Name : {{ item.name }}"
5257
with_items: "{{ _ec2_untagged_list }}"
5358

54-
5559
- name: Failed when some resources found
5660
fail:
57-
msg: "{% if (_ec2_ebs_list.volumes | length) > 0 %} EBS volumes to review: {{ _ec2_ebs_list_review | join(',') }} \n {% endif %} \
58-
{% if (_ec2_untagged_list | length) > 0 %} EC2 instances to review: \n {{ _ec2_list_review }} {% endif %} "
61+
msg: |
62+
{% if (_ec2_ebs_list.volumes | length) > 0 %} EBS volumes to review: {{ _ec2_ebs_list_to_review | join(',') }} {% endif %}
63+
{% if (_ec2_untagged_list | length) > 0 %} EC2 instances to review: \n {{ _ec2_list_to_review }} {% endif %}
5964
when: "{{ (_ec2_untagged_list | length > 0) or (_ec2_ebs_list.volumes | length >0) }}"

0 commit comments

Comments
 (0)