Created
May 23, 2021 03:59
-
-
Save nitesh8860/229fa07b7ccaaa6e91cc10d7ed58d1d8 to your computer and use it in GitHub Desktop.
creating inventory with tag values, filter.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws2 ec2 create-tags --resources $i --tags Key=SSM,Value=yes | |
aws2 ec2 associate-iam-instance-profile --instance-id $i --iam-instance-profile Name=SSMec2-Instance-Profile | |
aws ec2 associate-iam-instance-profile --instance-id i-0xxxxxxxxxx --iam-instance-profile Name=SSMec2-Instance-Profile | |
aws iam add-role-to-instance-profile --role-name AmazonEC2RoleforSSM --instance-profile-name SSMec2-Instance-Profile | |
aws iam remove-role-from-instance-profile --instance-profile-name SSMec2-Instance-Profile --role-name AmazonSSMRoleForInstancesQuickSetup | |
aws iam add-role-to-instance-profile --role-name AmazonEC2RoleforSSM --instance-profile-name SSMec2-Instance-Profile | |
aws2 ec2 describe-instances --filters Name=network-interface.addresses.private-ip-address,Values=[$i] \ | |
--query 'Reservations[*].Instances[*].{IP:PrivateIpAddress,Name:Tags[?Key==`Name`]|[0].Value}' \ | |
--output text | |
#Create inventory | |
aws2 ec2 describe-instances \ | |
--filters file://describe-instances-filter.json \ | |
--query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,IP:PrivateIpAddress,Key:KeyName}' \ | |
--output text | sort > inventory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment