Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Jinja variables in dynamic inventory regions configuration #1450

Open
1 task done
keenan-v1 opened this issue Apr 2, 2023 · 4 comments
Open
1 task done

Allow Jinja variables in dynamic inventory regions configuration #1450

keenan-v1 opened this issue Apr 2, 2023 · 4 comments
Labels
feature This issue/PR relates to a feature request needs_verified Some one might want to take a look at this and reproduce it to confirm

Comments

@keenan-v1
Copy link

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

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

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

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request needs_triage labels Apr 2, 2023
@alinabuzachis alinabuzachis added needs_verified Some one might want to take a look at this and reproduce it to confirm and removed needs_triage labels Apr 3, 2023
@mdavis-xyz
Copy link
Contributor

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:

TEMPLATABLE_OPTIONS = (
"access_key",
"secret_key",
"session_token",
"profile",
"iam_role_name",
)

and used here?

def get(self, *args):
value = self.original_options.get(*args)
if not value:
return value
if args[0] not in self.TEMPLATABLE_OPTIONS:
return value
if not self.templar.is_template(value):
return value
return self.templar.template(variable=value, disable_lookups=False)

@akira6592
Copy link
Contributor

Any updates?

I too would like to use templates withfilters.

@akira6592
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request needs_verified Some one might want to take a look at this and reproduce it to confirm
Projects
None yet
Development

No branches or pull requests

5 participants