I'm using AWSCLI at Windows 10 Professional with GitBash. I need to have a list of all running AWS instances by account. Will start doing in an account to make a list to populate the public keys from users.
Have based on these sites:
Add SSH Key to EC2 instances with Ansible – Automated
AWS documentation:
And have done:
aws ec2 describe-instances --filters Name=instance-state-name,Values=running
But the output from this command generate a lot of info. I tried to see the public IPs and generate a little less information, just to do a filtering test.
$ aws ec2 describe-network-interfaces --query NetworkInterfaces[].Association.PublicIp
[
"5.1.210.2",
"5.9.236.6",
"5.25.225.6",
"3.2.254.5",
"3.9.237.67",
"4.5.183.15",
"8.6.37.159",
"5.0.128.119",
"5.8.74.231",
"4.2.37.138",
"5.8.103.63",
"4.1.17.9",
"4.4.216.193",
"4.9.147.45",
"4.7.169.22"
]
For security purposes I did a change at some octecs. Becomes a better output and I can't figure out how to filter in a right way the 1st example.
My add-key.yml
[root@devops list]# cat add-key.yml
- name: "Playbook to Add Key to EC2 Instances"
hosts: hosts_to_add_key
vars:
- status : "present"
- key : "user_rsa_key.pub"
tasks:
- name: "Copy the authorized key file from"
authorized_key:
user: "{{ansible_user}}"
state: "{{status}}"
key: "{{ lookup('file', '{{ key }}')}}"
My hosts_to_add_key:
[root@devops list]# cat hosts_to_add_key
[hosts_to_add_key]
bacula ansible_host=3.2.1.43 ansible_user=centos
1.2.1.20 ansible_host=10.9.1.50 ansible_user=centos
devops ansible_host=localhost ansible_user=centos
docker ansible_host=52.87.108.170 ansible=ec2-user
jenkins ansible_host=52.7.6.214 ansible_user=ec2-user
jira ansible_host=54.175.104.102 ansible_user=ec2-user
[hosts_to_add_key:vars]
ansible_ssh_common_args="-o StrictHostKeyChecking=no"
Removed some hosts above to show few lines. If someone could point me out about describe-instances to get better results will be fine (by name, by VPC)
describe_instances()
in each account (and in each region if applicable).describe_instances()
.