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'





On Thursday, 14 November 2019 19:01:27 UTC+5:30, RAVITZ wrote:
>
> 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. 
>
> On Thu, Nov 14, 2019, 6:54 PM RAVITZ <[email protected] <javascript:>> 
> wrote:
>
>> Try with aws_profile=profile-in-awsconfig ansible-playbook playbookname 
>>
>> On Thu, Nov 14, 2019, 6:31 PM kingston vedanayagam <[email protected] 
>> <javascript:>> wrote:
>>
>>> 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.
>>>
>>>
>>> -- 
>>> 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 [email protected] <javascript:>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/9b79addd-9123-462e-ac7b-b3023e0fa307%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/9b79addd-9123-462e-ac7b-b3023e0fa307%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3cc01a11-6abd-48ec-9e4b-a6b707bd8dd6%40googlegroups.com.

Reply via email to