Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev find untagged #332

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Dev find untagged #332

wants to merge 1 commit into from

Conversation

MariuszJozwiak
Copy link
Contributor

To reduce cost script to find EC2 without MegaOps tags and unused EBS volumes. This scipt failed when found some resources without proper tags or EBS in state availabe (unassigned)

@MariuszJozwiak MariuszJozwiak force-pushed the dev-find-untagged branch 2 times, most recently from 2e5b599 to baafee3 Compare February 14, 2023 09:13
- hosts: localhost
connection: local
vars:
_ec2_whitelist:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitelist cannot be global in repo
it needs to be set per project
as this script will be executed on every project and because this is public repository also outside company

filters:
"tag:Infrastructure": 'mageops'
"tag:Tool": 'ansible'
instance-state-name: "{{ _ec2_filters }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is much more states than "running" and "stopped", ideally we would want to catch all of them
I would change it to not filter it here, instead later one ignore all that are in "terminated" state

- name: Generate list EC2 to review
set_fact:
_ec2_untagged_list: "{{ _ec2_untagged_list + [{ 'id' : item.instance_id, 'name' : item.tags.Name }] }}"
when: item.instance_id not in _ec2_whitelist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way we need to fetch instances twice to compare them
Better way would be to only list all instances
and then filter out instances that have correct tags/ids

- name: Find unused EBS volumes
ec2_vol_info:
filters:
status: "available"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is clever way to extract it 👍


- name: Set _ec2_list_review
set_fact:
_ec2_list_review: "{{ _ec2_list_review | default() + 'ID : ' + item.id + ' Name : ' + item.name + '\n' }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that syntax even works?
not sure what is going on here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to more readable

@MariuszJozwiak MariuszJozwiak force-pushed the dev-find-untagged branch 4 times, most recently from 320ac9c to bde9326 Compare February 14, 2023 13:10
… volumes. This scipt failed when found some resources without proper tags or EBS in state availabe (unassigned)

Signed-off-by: Mariusz Jóźwiak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants