'Ansible aws_ec2 inventory plugin - dynamic boto_profile
I am using the aws_ec2 inventory plugin and would like to pass the boto_profile in as a var at runtime.
I am trying to run the following command:
ansible-playbook playbook.yml --extra-vars profile=foo
Inside my aws_ec2.yml plugin file I have:
boto_profile: "{{ profile }}"
This returns the error:
The config profile ({{ profile }}) could not be found
I am able to use the profile var inside my playbook. I am using the ec2 module with profile: "{{ profile }}" That seems to work if I define a static inventory.
Is it possible to pass the profile var into the dynamic inventory file?
Solution 1:[1]
I'm using this in GitLab CI/CD and had the same issue, however you can look up the env variables in the dynamic inventory like this:
plugin: amazon.aws.aws_ec2
aws_access_key: "{{ lookup('env','AWS_ACCESS_KEY_ID') }}"
aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}"
regions:
- eu-central-1
groups:
webservers: "'app-server' in tags.Type"
and I cen set this up in the CI/CD under variables: and this is passed to docker container.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | VladoPortos |
