hello all
im upgrading python from 2.7 to python 3.7
and now I’m getting error when using aws API on module : module: ec2_instance_facts
- name: Get facts
local_action:
module: ec2_instance_facts
instance_ids:
- "xxxxxxx"
region: "xxxxxx"
register: instance
ansible --versionansible 2.7.0
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/home/ec2-user/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /home/ec2-user/app_virtualenv/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/app_virtualenv/bin/ansible
python version = 3.7.6 (default, Feb 26 2020, 20:54:15) [GCC 7.3.1 20180712 (Red Hat 7.3.1-6)]
ansible-config dump --only-changed
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = False
ANSIBLE_SSH_RETRIES(/etc/ansible/ansible.cfg) = 2
DEFAULT_CALLBACK_WHITELIST(/etc/ansible/ansible.cfg) = [‘profile_tasks’]
DEFAULT_LOAD_CALLBACK_PLUGINS(/etc/ansible/ansible.cfg) = True
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /home/ec2-user/app/logs/ansible.log
DEFAULT_PRIVATE_KEY_FILE(/etc/ansible/ansible.cfg) = /home/ec2-user/.ssh/DEV_VPN.pem
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = yaml
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
python -m site
sys.path = [
‘/home/ec2-user/app’,
‘/usr/lib64/python37.zip’,
‘/usr/lib64/python3.7’,
‘/usr/lib64/python3.7/lib-dynload’,
‘/home/ec2-user/app_virtualenv/lib64/python3.7/site-packages’,
‘/home/ec2-user/app_virtualenv/lib/python3.7/site-packages’,
]
USER_BASE: ‘/home/ec2-user/.local’ (exists)
USER_SITE: ‘/home/ec2-user/.local/lib/python3.7/site-packages’ (exists)
ENABLE_USER_SITE: False
`
the error I’m getting :
2020-05-02 11:54:57,580 p=23305 u=ec2-user | Saturday 02 May 2020 11:54:57 +0000 (0:00:00.476) 0:01:39.534 **********
2020-05-02 11:54:57,750 p=23305 u=ec2-user | Using module file /home/ec2-user/app_virtualenv/lib/python3.7/site-packages/ansible/modules/cloud/amazon/ec2_instance_facts.py
2020-05-02 11:54:58,120 p=23305 u=ec2-user | fatal: [10.0.5.187 → localhost]: FAILED! => changed=false
module_stderr: |-
/home/ec2-user/.ansible/tmp/ansible-tmp-1588420497.6072006-50705771655817/AnsiballZ_ec2_instance_facts.py:17: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module’s documentation for alternative uses
import imp
Traceback (most recent call last):
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1588420497.6072006-50705771655817/AnsiballZ_ec2_instance_facts.py”, line 113, in
_ansiballz_main()
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1588420497.6072006-50705771655817/AnsiballZ_ec2_instance_facts.py”, line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1588420497.6072006-50705771655817/AnsiballZ_ec2_instance_facts.py”, line 48, in invoke_module
imp.load_module(‘main’, mod, module, MOD_DESC)
File “/usr/lib64/python3.7/imp.py”, line 234, in load_module
return load_source(name, filename, file)
File “/usr/lib64/python3.7/imp.py”, line 169, in load_source
module = _exec(spec, sys.modules[name])
File “”, line 630, in _exec
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/tmp/ansible_ec2_instance_facts_payload_zmc16g7o/main.py”, line 555, in
File “/tmp/ansible_ec2_instance_facts_payload_zmc16g7o/main.py”, line 551, in main
File “/tmp/ansible_ec2_instance_facts_payload_zmc16g7o/main.py”, line 505, in list_ec2_instances
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/paginate.py”, line 449, in build_full_result
for response in self:
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/paginate.py”, line 255, in iter
response = self._make_request(current_kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/paginate.py”, line 332, in _make_request
return self._method(**current_kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/client.py”, line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/client.py”, line 648, in _make_api_call
operation_model, request_dict, request_context)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/client.py”, line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/endpoint.py”, line 102, in make_request
return self._send_request(request_dict, operation_model)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/endpoint.py”, line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/endpoint.py”, line 116, in create_request
operation_name=operation_model.name)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/hooks.py”, line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/hooks.py”, line 228, in emit
return self._emit(event_name, kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/hooks.py”, line 211, in _emit
response = handler(**kwargs)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/signers.py”, line 90, in handler
return self.sign(operation_name, request)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/signers.py”, line 157, in sign
auth.add_auth(request)
File “/home/ec2-user/app_virtualenv/lib/python3.7/site-packages/botocore/auth.py”, line 357, in add_auth
raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials
module_stdout: ‘’
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 1
`
Although i have the credentials in .aws dir
and when i doing ec2 simple API call I’m getting results :
python
`
Python 3.7.6 (default, Feb 26 2020, 20:54:15)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-6)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
import boto3
ec2_resource = boto3.resource(‘ec2’)
ec2_client = boto3.client(‘ec2’)
ec2_client.describe_instances()
{‘Reservations’: [{‘Groups’: , ‘Instances’: [{‘AmiLaunchIndex’: 0, ‘ImageId’: ‘ami-b66ed3de’, ‘InstanceId’: ‘i-be381945’, ‘InstanceType’: ‘m5.large’, ‘KeyName’: ‘DEV_VPN’, ‘LaunchTime’: datetime.datetime(2019, 3, 4, 8, 25, 17, tzinfo=tzlocal()), ‘Monitoring’: {‘State’: ‘disabled’}, ‘Placement’: {'Avail …
`