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 Environment Variables. But they fail to run in Tower because it exports another set of env. vars:
AWS_ACCESS_KEY
AWS_SECRET_KEY
In order to make them work in Tower just add the below in task definition:
environment:
AWS_ACCESS_KEY_ID: "{{ lookup('env','AWS_ACCESS_KEY') }}"
AWS_SECRET_ACCESS_KEY: "{{ lookup('env','AWS_SECRET_KEY') }}"
e.g. this task:
- name: Describe instances
command: aws ec2 describe-instances --region us-east-1
will transform to:
- 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') }}"
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.
get_facts) can be very helpful. - tedder42varsto make it less DRY. I am not related in any to the blog in question but it helped me. - mrlabbe