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

nb_inventory - Allow Jinja2 template on filter #834

Merged
merged 9 commits into from
Sep 28, 2022

Conversation

akira6592
Copy link
Contributor

@akira6592 akira6592 commented Sep 25, 2022

Related Issue

n/a

New Behavior

The nb_inventory inventory plugin's query_filters, device_query_filters, and query_filters options allow Jinja2 templates.

Contrast to Current Behavior

An example of option query_filters. Jinja2 Templates like the following are not available previously.

query_filters:
  - site: "{{ 'TEST-SITE' | lower }}"

This PR allows Jinja2 template and extra vars.

# ansible-playbook -i test_nb_inventory.yml -e e_site=test-site
...omitted...
query_filters:
  - site: "{{ e_site }}"   # using extra vars
...omitted...

Discussion: Benefits and Drawbacks

We can filter dynamically by specifying filter with extra vars. This can be expected to improve performance compared to retrieving the entire inventory and executing the playbook by specifying the group.

It is backwards-compatible. Strings that do not use Jinja2 templates are interpreted as normal strings.

Changes to the Documentation

Include the changes in this PR.

Proposed Release Note Entry

nb_inventory - Allow Jinja2 template on filter

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

@akira6592
Copy link
Contributor Author

I fixed conditional expression from 3.1 to 3.2 in tests/integration/targets/inventory-v3.2/runme.sh.
https://github.com/netbox-community/ansible_modules/pull/834/files#diff-da941c534001dc681682cf1403cf1230c459525f75a5914b8cfbf883f47a18a5

Should I have left it as 3.1?
Sorry, I still don't fully understand how testing works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants