Getting aws account id

394 views
Skip to first unread message

Darvin Denmian

unread,
May 17, 2016, 11:16:26 PM5/17/16
to ansible...@googlegroups.com
Hi guys,

does anyone have a good option to get the my aws account id using Ansible ?

Thanks !

Allen Sanabria

unread,
May 17, 2016, 11:32:39 PM5/17/16
to Ansible Project
You can use a Ansible Filter Plugin.

I have a repo with all of my filter plugins. Line 8 has the function you need.

def get_account_id(region):
    client
= boto3.client('iam', region_name=region)
   
try:
        account_id
= client.list_users()['Users'][0]['Arn'].split(':')[4]
       
return account_id
   
except Exception:
       
raise errors.AnsibleFilterError(
           
"Failed to retrieve account id"
       
)


https://github.com/linuxdynasty/ld-ansible-filters/blob/master/filter_plugins/aws.py#L8

Erick Vitor de Barros

unread,
May 17, 2016, 11:35:31 PM5/17/16
to ansible...@googlegroups.com
Thanks Allen, I'll give it a try !

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e5d91ca1-80bf-4652-aecd-8ea0feb77d9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages