title: How to run AWS CLI command tasks in Ansible Tower
body: <p>The AWS CLI command tasks in Ansible playbooks work fine form command line if AWS credentials are specified as environment variables as per boto requirements. More info can be found here <a href="http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment" rel="nofollow">Environment Variables</a>.
  But they fail to run in Tower because it exports another set of env. vars:</p>
  
  <pre><code>AWS_ACCESS_KEY
  AWS_SECRET_KEY
  </code></pre>
  
  <p>In order to make them work in Tower just add the below in task definition:</p>
  
  <pre><code>environment:
    AWS_ACCESS_KEY_ID: "{{ lookup('env','AWS_ACCESS_KEY') }}"
    AWS_SECRET_ACCESS_KEY: "{{ lookup('env','AWS_SECRET_KEY') }}"
  </code></pre>
  
  <p>e.g. this task:</p>
  
  <pre><code>- name: Describe instances
    command: aws ec2 describe-instances --region us-east-1
  </code></pre>
  
  <p>will transform to: </p>
  
  <pre><code>- name: Describe instances
    command: aws ec2 describe-instances --region us-east-1
    environment:
      AWS_ACCESS_KEY_ID: "{{ lookup('env','AWS_ACCESS_KEY') }}"
      AWS_SECRET_ACCESS_KEY: "{{ lookup('env','AWS_SECRET_KEY') }}"
  </code></pre>
  
  <p>NOTE: This only injects env.var. for the specific task - not the whole playbook!
  So you have to amend this way every AWS CLI task.</p>