AWS Ansible Python Boto - Profile Not Found Error

47 views
Skip to first unread message

kingston vedanayagam

unread,
Nov 14, 2019, 8:01:40 AM11/14/19
to Ansible Project
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 <module>\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:
---                                                  
- hosts: localhost                                  
  vars
:                                              
    sgname
: ansible_mumbai                          
    kpname
: mumbai                                  
    vmname
: apacheinstance                          
  tasks
:                                            
 
- name: creating security group and adding rules  
    ec2_group
:                                      
      aws_access_key
: "{{myaccesskey}}"              
      aws_secret_key
: "{{mysecretkey}}"              
      name
: "{{sgname}}"                            
      description
: ansible                          
      vpc_id
: "{{vpcid}}"                            
      region
: "{{region}}"                          
      rules
:                                        
       
-                                            
          proto
: tcp                                
          ports
:                                    
           
- 80                                      
           
- 22                                      
          cidr_ip
: 0.0.0.0/0                        
       
- rule_desc: allow all port on 80            
   
register: ansible_mumbai_output                  
 
- debug:                                          
     
var: ansible_mumbai_output                      
 
- name: creating linux instances                  
    ec2
:                                            
      aws_access_key
: "{{myaccesskey}}"              
      aws_secret_key
: "{{mysecretkey}}"              
      region
: "{{region}}"                          
      key_name
: "{{kpname}}"                        
      group_id
: "{{ansible_mumbai_output.group_id}}"
      instance_type
: "{{instancetype}}"              
      image
: "{{myami}}"                            
      vpc_subnet_id
: "{{subnet}}"                    
      assign_public_ip
: yes                          
      instance_tags
:                                
        name
: "{{vmname}}"                          
      count_tag
:                                    
        name
: "{{vmname}}"                          
      exact_count
: 1                                
      wait
: yes                                      
      wait_timeout
: 120                              
   
register: apacheinstance_output                  
 
- debug:                                          
     
var: apacheinstance_output                      
[root@ansibleserver playbooks]#  



Could some one help what is the error i am making here?
I see the module "ec2_group" is working fine with "boto3", which created the security group successfully. But the "ec2" module is failing. Please suggest.


RAVITZ

unread,
Nov 14, 2019, 8:24:34 AM11/14/19
to ansible...@googlegroups.com
Try with aws_profile=profile-in-awsconfig ansible-playbook playbookname 

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9b79addd-9123-462e-ac7b-b3023e0fa307%40googlegroups.com.

RAVITZ

unread,
Nov 14, 2019, 8:31:27 AM11/14/19
to ansible...@googlegroups.com
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. 
IMG20191114185827.jpg

kingston vedanayagam

unread,
Nov 14, 2019, 9:13:08 PM11/14/19
to Ansible Project
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'


To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

kingston vedanayagam

unread,
Nov 14, 2019, 9:39:01 PM11/14/19
to Ansible Project
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 ~]#

Dick Visser

unread,
Nov 15, 2019, 1:32:06 AM11/15/19
to ansible...@googlegroups.com
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:

Dick

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/29dce282-ebcb-4b96-ae00-9aa5828fa85b%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

kingston vedanayagam

unread,
Nov 19, 2019, 7:57:57 AM11/19/19
to Ansible Project
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.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

kingston vedanayagam

unread,
Nov 20, 2019, 9:16:26 PM11/20/19
to ansible...@googlegroups.com
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

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/iQ1fZDyGCzM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d63937d5-54b9-4cad-b8e0-53b53906b65d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages