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

Changed with/endwith behavior when passing variables to included template #81852

Closed
1 task done
mbialozor opened this issue Oct 3, 2023 · 4 comments
Closed
1 task done
Assignees
Labels
affects_2.15 bug This issue/PR relates to a bug. module This issue/PR relates to a module. verified This issue has been verified/reproduced by maintainer

Comments

@mbialozor
Copy link

mbialozor commented Oct 3, 2023

Summary

I'm not really sure if it's bug or feature. I'm also not really sure what cause this - Ansible itself, Jinja or Python. There's some changed behavior in templates when using include expression together with with/endwith block.

Variable:
camel_activemq_pool_max_connections: 50

Main template:

{% with
   var1=1,
   var2="2",
   var3=camel_activemq_pool_max_connections,
   var4="camel_activemq_pool_max_connections",
   var5='camel_activemq_pool_max_connections',
   var6="{{ camel_activemq_pool_max_connections }}",
   var7='{{ camel_activemq_pool_max_connections }}',
   var8="{% raw %}{{ camel_activemq_pool_max_connections }}{% endraw %}",
   var9='{% raw %}{{ camel_activemq_pool_max_connections }}{% endraw %}'
%}
{% include "common/liquibase.j2" %}
{% endwith %}

Included template:

var1: {{ var1 }}
var2: {{ var2 }}
var3: {{ var3 }}
var4: {{ var4 }}
var5: {{ var5 }}
var6: {{ var6 }}
var7: {{ var7 }}
var8: {{ var8 }}
var9: {{ var9 }}

Result on Amazon Linux 2023:

var1: 1
var2: 2
var3: 50
var4: camel_activemq_pool_max_connections
var5: camel_activemq_pool_max_connections
var6: 50
var7: 50
var8: {{ camel_activemq_pool_max_connections }}
var9: {{ camel_activemq_pool_max_connections }}

Result on Rocky Linux 8:

var1: 1
var2: 2
var3: 50
var4: camel_activemq_pool_max_connections
var5: camel_activemq_pool_max_connections
var6: {{ camel_activemq_pool_max_connections }}
var7: {{ camel_activemq_pool_max_connections }}
var8: {% raw %}{{ camel_activemq_pool_max_connections }}{% endraw %}
var9: {% raw %}{{ camel_activemq_pool_max_connections }}{% endraw %}

The differences we observe:

  1. {{ }} markers are interpreted differently inside with/endwith block - on Rocky Linux 8 they are interpreted as part of string.
  2. raw/endraw block is also interpreted as part of string.

Issue Type

Bug Report

Component Name

template

Ansible Version

Amazon Linux 2023:

(root@al2023 ansible-jenkins)$ ansible --version
ansible [core 2.15.3]
  config file = /u01/package/repository/config/ansible-workspace/ansible-jenkins/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, Sep  8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Rocky Linux 8:

(root@rl8 ansible-jenkins)# ansible --version
ansible [core 2.14.2]
  config file = /u01/package/repository/config/ansible-workspace/ansible-jenkins/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible
  python version = 3.11.2 (main, Jun 22 2023, 04:35:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all

OS / Environment

Recent releases of:

  • Amazon Linux 2023
  • Rocky Linux 8

Steps to Reproduce

To generate file using the templates from the description.

Expected Results

Not sure what should be the expected result, I mean which version generates file correctly. Personally I prefer the Amazon Linux 2023 option (despite it requires refactoring of our templates). In general, I expect consisted behavior between versions. What's interesting, both setups use the same Jinja versions. Ansible and Python are different.

Actual Results

Described in the summary.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. affects_2.15 module This issue/PR relates to a module. labels Oct 3, 2023
@ansibot
Copy link
Contributor

ansibot commented Oct 3, 2023

Files identified in the description:

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

@s-hertel s-hertel added needs_verified This issue needs to be verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Oct 10, 2023
@sivel
Copy link
Member

sivel commented Oct 10, 2023

The behavior changed as part of #78713

I believe the 2.15+ behavior is correct, but will solicit additional input from others.

@mkrizek
Copy link
Contributor

mkrizek commented Oct 12, 2023

I also think that the current (2.15+) behavior is correct.

@Akasurde
Copy link
Member

Closing this as per the above comment. Please feel free to open a new issue if the problem persists. Thanks.

@Akasurde Akasurde added verified This issue has been verified/reproduced by maintainer and removed needs_verified This issue needs to be verified/reproduced by maintainer labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.15 bug This issue/PR relates to a bug. module This issue/PR relates to a module. verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

No branches or pull requests

7 participants