title: Packer | Ansible | NoCredentialsError: Unable to locate credentials
body: <p>I am trying to execute ansible script via Packer to Obtain EFS facts. Within my packer.json I am passing AWS_ACCESS_KEY_ID/KEY/TOKEN. My facts.yml works fine if I execute it individually by passing <code>-sts_assume_role</code> in my code.</p>
  <p>As suggested by @error404 I have added sts_assume_role task and received updated logs to the question.</p>
  <p>tasks/facts.yml:</p>
  <pre><code># Get all RDS instances
  ---
  
  - sts_assume_role:
      region: &quot;central&quot;
      role_arn: &quot;arn:aws:iam::12345678919:role/jenkins&quot;
      role_session_name: &quot;ansible-connect&quot;
    register: assumed_role
  
  - name: Obtain all EFS facts
    efs_facts:
      aws_access_key: &quot;{{ assumed_role.sts_creds.access_key }}&quot;
      aws_secret_key: &quot;{{ assumed_role.sts_creds.secret_key }}&quot;
      security_token: &quot;{{ assumed_role.sts_creds.session_token }}&quot;
      region: &quot;eu-central-1&quot;
    register: airflow_efs_facts
  
  - debug:
      var: airflow_efs_facts.ansible_facts.efs[0].filesystem_address
  </code></pre>
  <p>my packer.json</p>
  <pre><code>{
    &quot;variables&quot;: {
      &quot;aws_region&quot;: &quot;eu-central-1&quot;,
      &quot;kms_key_id&quot;: &quot;{{env `KEY`}}&quot;,
      &quot;aws_access_key&quot;: &quot;{{env `AWS_ACCESS_KEY_ID`}}&quot;,
      &quot;aws_secret_key&quot;: &quot;{{env `AWS_SECRET_ACCESS_KEY`}}&quot;,
      &quot;aws_session_token&quot;: &quot;{{env `AWS_SESSION_TOKEN`}}&quot;,
      &quot;subnet_id&quot;: &quot;{{env `SUBNET`}}&quot;,
      &quot;vpc_id&quot;: &quot;{{env `VPC`}}&quot;
    },
    &quot;builders&quot;: [
      {
        &quot;type&quot;: &quot;amazon-ebs&quot;,
        &quot;access_key&quot;: &quot;{{user `aws_access_key`}}&quot;,
        &quot;secret_key&quot;: &quot;{{user `aws_secret_key`}}&quot;,
        &quot;token&quot;: &quot;{{user `aws_session_token`}}&quot;,
        &quot;region&quot;: &quot;{{user `aws_region`}}&quot;,
        &quot;vpc_id&quot;: &quot;{{user `vpc_id`}}&quot;,
        &quot;subnet_id&quot;: &quot;{{user `subnet_id`}}&quot;,
  
        &quot;source_ami_filter&quot;: {
          &quot;filters&quot;: {
              &quot;name&quot;: &quot;ec2-*&quot;,
              &quot;virtualization-type&quot;: &quot;hvm&quot;,
              &quot;root-device-type&quot;: &quot;ebs&quot;
          },
          &quot;owners&quot;: &quot;self&quot;,
          &quot;most_recent&quot;: true
        },
        &quot;encrypt_boot&quot;: &quot;true&quot;,
        &quot;kms_key_id&quot;: &quot;{{user `kms_key_id`}}&quot;,
        &quot;instance_type&quot;: &quot;t2.large&quot;,
        &quot;ssh_username&quot;: &quot;ec2-user&quot;,
        &quot;ami_block_device_mappings&quot;: [
          {
            &quot;device_name&quot;: &quot;/dev/xvda&quot;,
            &quot;volume_size&quot;: 20,
            &quot;volume_type&quot;: &quot;gp2&quot;,
            &quot;delete_on_termination&quot;: true
          }
        ],
        &quot;launch_block_device_mappings&quot;: [
           {
              &quot;device_name&quot;: &quot;/dev/xvda&quot;,
              &quot;volume_size&quot;: 20,
              &quot;volume_type&quot;: &quot;gp2&quot;,
              &quot;delete_on_termination&quot;: true
           }
      ],
        &quot;ami_description&quot;: &quot;Master AMI to be used to build Server&quot;,
        &quot;ami_name&quot;: &quot;master-{{isotime \&quot;2006-01-02\&quot;}}&quot;,
        &quot;tags&quot;: {
          &quot;Name&quot;: &quot;master-baseline&quot;,
          &quot;ami_version&quot;: &quot;{{isotime \&quot;2006-01-02\&quot;}}&quot;,
          &quot;ami_cis_benchmark_version&quot;: &quot;1.0.0&quot;,
          &quot;ami_os&quot;: &quot;amazon&quot;
        }
      }
    ],
    &quot;provisioners&quot;: [
      {
        &quot;inline&quot;: [
          &quot;sudo yum -y install bzip2 python-pip vim wget curl mlocate unzip git  java-1.8.0-openjdk-devel java-1.8.0-openjdk jq&quot;,
          &quot;sudo updatedb&quot;,
          &quot;sudo pip install ansible&quot;,
          &quot;sudo yum -y install python3 python3-pip python3-devel python3-setuptools&quot;,
          &quot;sudo yum -y update&quot;
        ],
        &quot;type&quot;: &quot;shell&quot;
      },
      {
        &quot;type&quot;: &quot;ansible-local&quot;,
        &quot;playbook_file&quot;: &quot;ansible/plays/install.yml&quot;,
        &quot;role_paths&quot;: [
              &quot;ansible/roles/master&quot;
        ]
      }
    ]
  }
  </code></pre>
  <p><strong>Below is the error message:</strong></p>
  <blockquote>
  <p>[0;32m    amazon-ebs: TASK [roles/airflow-master : sts_assume_role]
  **********************************[0m [0;32m    amazon-ebs: [0;31mAn exception occurred during task execution. To see the full traceback,
  use -vvv. The error was: botocore.exceptions.NoCredentialsError:
  Unable to locate credentials[0m[0m [0;32m    amazon-ebs: [0;31mfatal:
  [127.0.0.1]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;module_stderr&quot;: &quot;Traceback
  (most recent call last):\n  File
  &quot;/home/ec2-user/.ansible/tmp/ansible-tmp-1560349713.84-28986519228608/AnsiballZ_sts_assume_role.py&quot;,
  line 114, in \n    _ansiballz_main()\n  File
  &quot;/home/ec2-user/.ansible/tmp/ansible-tmp-1560349713.84-28986519228608/AnsiballZ_sts_assume_role.py&quot;,
  line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path,
  ANSIBALLZ_PARAMS)\n  File
  &quot;/home/ec2-user/.ansible/tmp/ansible-tmp-1560349713.84-28986519228608/AnsiballZ_sts_assume_role.py&quot;,
  line 49, in invoke_module\n</p>
  </blockquote>