# AWS Ansible Python Boto - Profile Not Found Error

**URL:** <https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [November 14, 2019, 1:01pm UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658 "2019-11-14T13:01:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingston\_vedanayagam](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kingston\_vedanayagam](https://forum.ansible.com/u/kingston_vedanayagam)\
**Post date:** [November 14, 2019, 1:01pm UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/1 "2019-11-14T13:01:40Z")

</div>

Hi All,

I have a simple playbook to create an EC2 instance in my account which is failing with “ProfileNotFoundError” when runs.

> 

[root@ansibleserver ~]# cat /etc/system-release  
CentOS Linux release 7.6.1810 (Core)  
[root@ansibleserver ~]# ansible --version  
ansible 2.4.2.0  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]  
[root@ansibleserver ~]# python --version  
Python 2.7.5  
[root@ansibleserver ~]# rpm -qa |grep -i boto  
python-boto3-1.4.6-5.el7.noarch  
python-boto-2.25.0-2.el7.centos.noarch

> 

Error:

> fatal: [localhost]: FAILED! =\> {  
> “changed”: false,  
> “module\_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible\_AeceaE/ansible\_module\_ec2.py", line 1725, in \n main()\n File "/tmp/ansible\_AeceaE/ansible\_module\_ec2.py", line 1673, in main\n ec2 = ec2\_connect(module)\n File "/tmp/ansible\_AeceaE/ansible\_modlib.zip/ansible/module\_utils/ec2.py", line 320, in ec2\_connect\nAttributeError: ‘module’ object has no attribute ‘ProfileNotFoundError’\n”,

Command:

> > ansible-playbook /etc/ansible/playbooks/aws\_deployvm\_vm.yml -e ‘vpcid=vpc-1fb78577 region=ap-south-1 myaccesskey=sometext mysecretkey=“sometext” subnet=subnet-e283d88a myami=ami-040c7ad0a93be494e instancetype=t2.micro’

Playbook:

`

---

<div class="post-metadata">

**Author:** ![RAVITZ](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@RAVITZ](https://forum.ansible.com/u/RAVITZ)\
**Post date:** [November 14, 2019, 1:24pm UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/2 "2019-11-14T13:24:13Z")

</div>

Try with aws\_profile=profile-in-awsconfig ansible-playbook playbookname

---

<div class="post-metadata">

**Author:** ![RAVITZ](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@RAVITZ](https://forum.ansible.com/u/RAVITZ)\
**Post date:** [November 14, 2019, 1:30pm UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/3 "2019-11-14T13:30:48Z")

</div>

Hi Kingston,

If you can see attached image, in my case though those secret keys won’t work now, profile is PERSONAL.  
Boto checks for profile in /.aws/credentials file.

> **(attachments)**
>
> ![IMG20191114185827.jpg](https://us1.discourse-cdn.com/ansible/original/2X/8/8abddd38a524b9e258667509679283de1a98d017.jpeg)

---

<div class="post-metadata">

**Author:** ![kingston\_vedanayagam](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kingston\_vedanayagam](https://forum.ansible.com/u/kingston_vedanayagam)\
**Post date:** [November 15, 2019, 2:13am UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/4 "2019-11-15T02:13:08Z")

</div>

Hi Ravi,

Thanks for helping…  
I am still getting the same error even after mentioned the profile name.

`  
[root@ansibleserver ~]# cat .aws/credentials  
[user1]  
aws\_access\_key\_id = 6JO2WH2PH4Q  
aws\_secret\_access\_key = Ky2laT9PwJSqBjDK5  
[user2]  
aws\_access\_key\_id = JOQNXRWYHM  
aws\_secret\_access\_key = gK8stl+rOYYoGGg  
[root@ansibleserver ~]# cat .aws/config  
[profile user1]  
region = ap-south-1  
[profile user2]  
region = ap-south-1  
[root@ansibleserver ~]#

Command Used:

aws\_profile=user2 ansible-playbook /etc/ansible/playbooks/aws\_deployvm\_vm.yml -e ‘vpcid=vpc-1fb78577 region=ap-south-1 myaccesskey=NXRWYHM mysecretkey=“E748x5” subnet=subnet-e283d88a myami=ami-040c7ad0a93be494e instancetype=t2.micro’

`

---

<div class="post-metadata">

**Author:** ![kingston\_vedanayagam](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kingston\_vedanayagam](https://forum.ansible.com/u/kingston_vedanayagam)\
**Post date:** [November 15, 2019, 2:39am UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/5 "2019-11-15T02:39:01Z")

</div>

Following command doesn’t return any output. Is that fine?

[root@ansibleserver ~]# python /usr/lib/python2.7/site-packages/ansible/module\_utils/ec2.py --list --profile user2  
[root@ansibleserver ~]# python /usr/lib/python2.7/site-packages/ansible/module\_utils/ec2.py --list --profile user1  
[root@ansibleserver ~]# python /usr/lib/python2.7/site-packages/ansible/module\_utils/ec2.py --list  
[root@ansibleserver ~]#

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 15, 2019, 6:31am UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/6 "2019-11-15T06:31:41Z")

</div>

You appear to have searched for (and found) a file called ec2.py in the ansible code tree.

It’s part of the code and not meant to be run like that.

If you intended to use the ec2.py dynamic inventory script, the docs are clear where to get that:

[https://docs.ansible.com/ansible/latest/user\_guide/intro\_dynamic\_inventory.html](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html)

Dick

---

<div class="post-metadata">

**Author:** ![kingston\_vedanayagam](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kingston\_vedanayagam](https://forum.ansible.com/u/kingston_vedanayagam)\
**Post date:** [November 19, 2019, 12:57pm UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/7 "2019-11-19T12:57:57Z")

</div>

Thanks Dick for the response. I understood that ec2.py can’t be executed in that way.  
However, i have resolved my “Profile Not Found” issue by using ec2\_instance module after upgrading ansible from 2.4 to 2.9.

Thanks Ravi for your help.

---

<div class="post-metadata">

**Author:** ![kingston\_vedanayagam](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kingston\_vedanayagam](https://forum.ansible.com/u/kingston_vedanayagam)\
**Post date:** [November 21, 2019, 2:15am UTC](https://forum.ansible.com/t/aws-ansible-python-boto-profile-not-found-error/31658/8 "2019-11-21T02:15:47Z")

</div>

EC2 module is also working to spin instances from ansible.  
Following are the ansible/boto versions being used now.

#python-boto3-1.4.6-5.el7.noarch  
#python2-boto-2.45.0-3.el7.noarch  
#ansible-2.9.0-1.el7.noarch  
Python 2.7.5
