# Setting aws\_access\_key/aws\_secret\_key in AWS Dyn Inventory config doesn't work?

**URL:** <https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566>\
**Category:** Get Help\
**Tags:** ubuntu, aws\
**Created:** [September 29, 2024, 3:33pm UTC](https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566 "2024-09-29T15:33:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artem\_Vakhitov](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/artem_vakhitov/32/4864_2.png) [@Artem\_Vakhitov](https://forum.ansible.com/u/Artem_Vakhitov)\
**Post date:** [September 29, 2024, 3:33pm UTC](https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566/1 "2024-09-29T15:33:25Z")

</div>

Ubuntu 22.04 VM, Ansible 2.16.11 from PPA, amazon.aws 8.2.1 here.

The official docs ([Dynamic Inventory Plugin — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/amazon/aws/docsite/aws_ec2_guide.html) ) state that you can do this:

```auto
# demo.aws_ec2.yml
plugin: amazon.aws.aws_ec2

# The access key for your AWS account.
aws_access_key: <YOUR-AWS-ACCESS-KEY-HERE>
# The secret access key for your AWS account.
aws_secret_key: <YOUR-AWS-SECRET-KEY-HERE>

```

Now, it’s not my intention to pass credentials in cleartext, I’m just learning/researching/debugging here. The fact is, I can’t get it to work with the variables set directly in the AWS Dynamic Inventory config file (aws\_ec2.yml). Tried it with and without quotes. I’m getting the following error:

```auto
 ansible-playbook --flush-cache lsn13.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Create AWS instances] *************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************
ok: [localhost]

TASK [Create instances] *****************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: botocore.exceptions.NoCredentialsError: Unable to locate credentials
failed: [localhost] (item=build) => {"ansible_loop_var": "item", "boto3_version": "1.35.26", "botocore_version": "1.35.26", "changed": false, "item": "build", "msg": "Could not describe default VPC: Unable to locate credentials"}

```

Note that the plugin config seems to have been parsed successfully, the error occurs when trying to create an instance.

Is what I’m trying to do just not supported anymore?

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [September 29, 2024, 4:21pm UTC](https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566/2 "2024-09-29T16:21:17Z")

</div>

Your mistake is assuming that setting the credentials for the inventory plugin is in any way related to module execution. It’s not. Those credential settings are only used by the inventory plugin itself.

---

<div class="post-metadata">

**Author:** ![Artem\_Vakhitov](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/artem_vakhitov/32/4864_2.png) [@Artem\_Vakhitov](https://forum.ansible.com/u/Artem_Vakhitov)\
**Post date:** [September 29, 2024, 4:42pm UTC](https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566/3 "2024-09-29T16:42:28Z")

</div>

Ah, I see. I was confused by the fact that AWS credentials set as environmental variables worked for both.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 29, 2024, 4:42pm UTC](https://forum.ansible.com/t/setting-aws-access-key-aws-secret-key-in-aws-dyn-inventory-config-doesnt-work/9566/4 "2024-10-29T16:42:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
