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:
`
RAVITZ
(RAVITZ)
November 14, 2019, 1:24pm
2
Try with aws_profile=profile-in-awsconfig ansible-playbook playbookname
RAVITZ
(RAVITZ)
November 14, 2019, 1:30pm
3
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)
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’
`
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 ~]#
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
Dick
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.
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