Skip to content

Allow to load vars with expressions evaluated lazily #229

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

felixfontein
Copy link
Collaborator

@felixfontein felixfontein commented Mar 13, 2025

With Data Tagging, this is finally possible for community.sops.load_vars.

Unfortunately, the DT PR also deprecates top-level facts, so every time you use anything loaded by community.sops.load_vars, you get a big fat deprecation warning 😭 (This has been pushed to ansible-core 2.20.)

I hope it's possible to either add an API so that action plugins can finally set variables, or move the deprecation to a later ansible-core version until such an API exists.

(This PR currently contains #225.)

@felixfontein
Copy link
Collaborator Author

felixfontein commented Mar 13, 2025

(Obviously the integration tests currently fail with devel, since that branch also has version 2.19, but doesn't have data tagging...)

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.80%. Comparing base (e4c372c) to head (c479abd).

Files with missing lines Patch % Lines
plugins/action/load_vars.py 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   83.80%   83.80%   -0.01%     
==========================================
  Files          12       12              
  Lines         735      747      +12     
  Branches      143      150       +7     
==========================================
+ Hits          616      626      +10     
- Misses         84       85       +1     
- Partials       35       36       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

github-actions bot commented Mar 13, 2025

Docs Build 📝

Thank you for contribution!✨

The docs for this PR have been published here:
https://ansible-collections.github.io/community.sops/pr/229

You can compare to the docs for the main branch here:
https://ansible-collections.github.io/community.sops/branch/main

The docsite for this PR is also available for download as an artifact from this run:
https://github.com/ansible-collections/community.sops/actions/runs/14550036762

File changes:

Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/community.sops/community.sops/docsbuild/base/load_vars_module.html b/home/runner/work/community.sops/community.sops/docsbuild/head/load_vars_module.html
index ba62a41..3cae551 100644
--- a/home/runner/work/community.sops/community.sops/docsbuild/base/load_vars_module.html
+++ b/home/runner/work/community.sops/community.sops/docsbuild/head/load_vars_module.html
@@ -277,11 +277,12 @@ see <a class="reference internal" href="#ansible-collections-community-sops-load
 <td><div class="ansible-option-cell"><p>This option controls how Jinja2 expressions in values in the loaded file are handled.</p>
 <p>If set to <code class="ansible-value docutils literal notranslate"><span class="pre">ignore</span></code>, expressions will not be evaluated, but treated as regular strings.</p>
 <p>If set to <code class="ansible-value docutils literal notranslate"><span class="pre">evaluate-on-load</span></code>, expressions will be evaluated on execution of this module, in other words, when the file is loaded.</p>
-<p>Unfortunately, there is no way for non-core modules to handle expressions “unsafe”, in other words, evaluate them only on use. This can only achieved by <a class="reference external" href="https://docs.ansible.com/ansible/devel/collections/ansible/builtin/include_vars_module.html#ansible-collections-ansible-builtin-include-vars-module" title="(in Ansible vdevel)"><span class="xref std std-ref">ansible.builtin.include_vars</span></a>, which unfortunately cannot handle SOPS-encrypted files.</p>
+<p>If set to <code class="ansible-value docutils literal notranslate"><span class="pre">lazy-evaluation</span></code>, expressions will be lazily evaluated. This requires ansible-core 2.19 or newer and is the same behavior than <a class="reference external" href="https://docs.ansible.com/ansible/devel/collections/ansible/builtin/include_vars_module.html#ansible-collections-ansible-builtin-include-vars-module" title="(in Ansible vdevel)"><span class="xref std std-ref">ansible.builtin.include_vars</span></a>. <code class="ansible-value docutils literal notranslate"><span class="pre">lazy-evaluation</span></code> has been added in community.sops 2.1.0.</p>
 <p class="ansible-option-line"><strong class="ansible-option-choices">Choices:</strong></p>
 <ul class="simple">
 <li><p><code class="ansible-option-default-bold docutils literal notranslate"><strong><span class="pre">&quot;ignore&quot;</span></strong></code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
 <li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">&quot;evaluate-on-load&quot;</span></code></p></li>
+<li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">&quot;lazy-evaluation&quot;</span></code></p></li>
 </ul>
 </div></td>
 </tr>

@felixfontein felixfontein force-pushed the dt-vars branch 2 times, most recently from 51042a9 to 9d0075f Compare March 30, 2025 19:51
@felixfontein felixfontein changed the title [WIP] Allow to load vars with expressions evaluated lazily Allow to load vars with expressions evaluated lazily Apr 19, 2025
@felixfontein
Copy link
Collaborator Author

I think this is ready, but I don't want to merge this before ansible-core 2.19 rc1 is out.

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.

1 participant