# Manage multiple aws accounts with ansible playbook using ec2.py/ec2.ini

**URL:** <https://forum.ansible.com/t/manage-multiple-aws-accounts-with-ansible-playbook-using-ec2-py-ec2-ini/29917>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [March 20, 2019, 5:35am UTC](https://forum.ansible.com/t/manage-multiple-aws-accounts-with-ansible-playbook-using-ec2-py-ec2-ini/29917 "2019-03-20T05:35:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![naga\_babu](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@naga\_babu](https://forum.ansible.com/u/naga_babu)\
**Post date:** [March 20, 2019, 5:35am UTC](https://forum.ansible.com/t/manage-multiple-aws-accounts-with-ansible-playbook-using-ec2-py-ec2-ini/29917/1 "2019-03-20T05:35:45Z")

</div>

I have multiple aws accounts. I would like to manage all these accounts using ansible playbooks. ex. provisioning new machines etc…

But when I use profile/AWS\_PROFILE option it always taking default profile not going to specified profiles.

It says specified vpc does not exist as it is checking under default profile from ~/.aws./credentials or ~/.boto files

Please let me know how can I manage multiple aws accounts using ansible playbooks.

I have installed boto3 using pip on my machine.,

p.s. I am using all these playbooks from one of the ec2 machine. This is from default profile location.

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![Shrinath\_Mangalore](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Shrinath\_Mangalore](https://forum.ansible.com/u/Shrinath_Mangalore)\
**Post date:** [March 20, 2019, 7:54am UTC](https://forum.ansible.com/t/manage-multiple-aws-accounts-with-ansible-playbook-using-ec2-py-ec2-ini/29917/2 "2019-03-20T07:54:33Z")

</div>

Hi Naga,

One of the google doc says that …

From Example: AWS EC2 External Inventory Script([https://docs.ansible.com/ansible/latest/user\_guide/intro\_dynamic\_inventory.html#example-aws-ec2-external-inventory-script](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script))

If you use Boto profiles to manage multiple AWS accounts, you can pass --profile PROFILE name to the ec2.py script. An example profile might be:

[profile dev]  
aws\_access\_key\_id =   
aws\_secret\_access\_key =

[profile prod]  
aws\_access\_key\_id =   
aws\_secret\_access\_key =   
You can then run ec2.py --profile prod to get the inventory for the prod account, although this option is not supported by ansible-playbook. You can also use the AWS\_PROFILE variable - for example:

AWS\_PROFILE=prod ansible-playbook -i ec2.py myplaybook.yml

Hope this helps.

-Thanks  
Shrinath

---

<div class="post-metadata">

**Author:** ![naga\_babu](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@naga\_babu](https://forum.ansible.com/u/naga_babu)\
**Post date:** [March 20, 2019, 7:59am UTC](https://forum.ansible.com/t/manage-multiple-aws-accounts-with-ansible-playbook-using-ec2-py-ec2-ini/29917/3 "2019-03-20T07:59:25Z")

</div>

Thanks Shrinath.

I have tried with that option.

I am able to get all the inventory info when I tried like ./ec2.py --list --profile=prod

but whey I tried with AWS\_PROFILE=prod ansible-playbook -i ec2.py myplaybook.yml to create new ec2 instance under prod account it says subnet/groups not found.

which means it’s checking under default profile not under prod account.
