ansible-collections / amazon.aws

Ansible Collection for Amazon AWS
GNU General Public License v3.0
309 stars 340 forks source link

Allow Jinja variables in dynamic inventory regions configuration #1450

Open keenan-v1 opened 1 year ago

keenan-v1 commented 1 year ago

Summary

I am trying to make an inventory configuration using the aws_ec2 and aws_rds plugins. Using best practices with IaC, I pass my region in as a variable. I discovered that the following does not currently work:

The error is that {{ aws_region }} is not a valid region, which is correct. I expected it to replace the value with the desired region.

Issue Type

Feature Idea

Component Name

aws_rds, aws_ec2 inventory plugins

Additional Information

I would like this to work:

plugin: amazon.aws.aws_rds
statuses:
  - available
regions:
  - "{{ aws_region }}"

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

mdavis-xyz commented 1 year ago

I'm having a similar problem with a different field (filters) that I expect to be templated but isn't.

@s-hertel I don't understand why some fields are templated and some aren't. I'm trying to spot the difference in the code. Is it TEMPLATABLE_OPTIONS? Defined here:

https://github.com/ansible-collections/amazon.aws/blob/f399fb763b419e9a57bac1045f7af7340f39fcc1/plugins/plugin_utils/inventory.py#L31-L37

and used here?

https://github.com/ansible-collections/amazon.aws/blob/f399fb763b419e9a57bac1045f7af7340f39fcc1/plugins/plugin_utils/inventory.py#L49-L58

akira6592 commented 10 months ago

Any updates?

I too would like to use templates withfilters.

akira6592 commented 8 months ago

@keenan-v1 Hello.

By #1980, the region and regions parameters are support template.

It will be included in a future release.

inventory_aws_ec2.yml:

---
plugin: aws_ec2
regions: 
  - "{{ lookup('env', 'AWS_REGION') }}"
hostnames:
  - tag:Name
% AWS_REGION=ap-northeast-1 ansible-inventory -i inventory_aws_ec2.yml --graph 
@all:
  |--@ungrouped:
  |--@aws_ec2:
  |  |--my_instance1

However, --extra-vars is still not supported.