Normally, when we are using ansible ec2 module to do operations, it is like this:
- name: Creating ELB
ec2_elb_lb:
aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
region: "{{ AWS_REGION }}"
state: present
name: "{{ item.name }}"
...
However, it will expose AWS Key pairs directly in source code. So I tried to attach IAM role to AWS EC2.
But I don't know how does ansible ec2 module use IAM role to get permissions to operate aws resources(such as create new ELB) if
aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
are not passed to ec2 module.
Can anyone help me with this? How can I implement this function if using IAM role?