JInja Warning using when condition

97 views
Skip to first unread message

Sreejith Sreejayan

unread,
Jul 19, 2018, 2:29:14 AM7/19/18
to Ansible Project
any way to avoid jinja warning in when condition [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: '{{ tomcat.resweb.version }}-{{ tomcat.resweb.build }}' not in webpage.content  
 #used the alternative solution tomcat.resweb.version  ~ '-' ~ tomcat.resweb.build not in webpage.content but its not taking the value from the variable file

Kai Stian Olstad

unread,
Jul 19, 2018, 3:42:23 AM7/19/18
to ansible...@googlegroups.com
Just a few days ago you said that it work with parenthesis ref
https://groups.google.com/forum/#!msg/ansible-project/Zd-q59A3DQY/wd5rIeVYCQAJ

so that is not true anymore?

--
Kai Stian Olstad

Sreejith Sreejayan

unread,
Jul 19, 2018, 5:36:36 AM7/19/18
to ansible...@googlegroups.com
nope is not not taking the value from the variable file task getting failed



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0325556f45ffbfabde7be6619cd23f04%40olstad.com.

For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Jul 20, 2018, 3:54:41 AM7/20/18
to ansible...@googlegroups.com
On 19.07.2018 11:35, Sreejith Sreejayan wrote:
> nope is not not taking the value from the variable file task getting
> failed

Then you must have some errors in your code, because this is something
that people use every day.
But since you haven't shared any code it is impossible to help.

--
Kai Stian Olstad

Sreejith Sreejayan

unread,
Jul 20, 2018, 6:37:31 AM7/20/18
to ansible...@googlegroups.com
this is task code
- name: Fail when the version does not match
  action: fail
  when: tomcat.resweb.version~ '-' ~tomcat.resweb.build not in webpage.content
  register: version_check


 Debug log
TASK [resweb : Fail when the version does not match] *************************************************************************************************
task path: /home/vj7h/allegiant_git/sdlc_deploy/roles/resweb/tasks/main.yml:158
fatal: [lhqqa1rwbws01.qa1.allegiantair.com]: FAILED! => {
    "changed": false,
    "msg": "Failed as requested from task"
}
...ignoring
META: ran handlers
META: ran handlers
Read vars_file 'vars/versions.yml'
skipping vars_file 'vars/{{ ansible_domain }}/jboss_properties_vars_commercial.yml' due to an undefined variable





--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Jul 20, 2018, 7:01:54 AM7/20/18
to ansible...@googlegroups.com
On 20.07.2018 12:36, Sreejith Sreejayan wrote:
> this is task code
> - name: Fail when the version does not match
> action: fail
> when: tomcat.resweb.version~ '-' ~tomcat.resweb.build not in
> webpage.content
> register: version_check

And if you set these three task before this fail task, what is the
output of them.

- debug: var=tomcat.resweb.version
- debug: var=tomcat.resweb.build
- debug: var=webpage.content


--
Kai Stian Olstad

Sreejith Sreejayan

unread,
Jul 20, 2018, 7:30:22 AM7/20/18
to ansible...@googlegroups.com
TASK [resweb : debug] ********************************************************************************************************************************
task path: /home/tasks/main.yml:157
ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
    "tomcat.resweb.version": "2.61.1"
}

TASK [resweb : debug] ********************************************************************************************************************************
task path: /home/tasks/main.yml:158
ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
    "tomcat.resweb.build": "d478a03"
}
Read vars_file 'vars/versions.yml'
Read vars_file 'vars/yum_logic.yml'

TASK [resweb : debug] ********************************************************************************************************************************
task path: /home/tasks/main.yml:159
ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
    "webpage.content": "<!doctype html>\n\n\n\n<html>\n<head>\n    \n    <script type=\"text/javascript\" src=\"js/jquery-1.7.1.min.js\"></script>\n    <script type=\"text/javascript\">\n\n        var resWebVersion = \"2.62.4-7ca3135 (Build DateTime: 2018-07-03T05:53:23)\
Read vars_file 'vars/versions.yml'
Read vars_file 'vars/yum_logic.yml'






--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Sreejith Sreejayan

unread,
Jul 20, 2018, 7:50:00 AM7/20/18
to ansible...@googlegroups.com
- debug: var="{{ tomcat.resweb.version~ '-' ~tomcat.resweb.build }}"

TASK [resweb : debug] ********************************************************************************************************************************
task path: /home/vj7h/allegiant_git/sdlc_deploy/roles/resweb/tasks/main.yml:157
ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
    "2.61.1-d478a03": "VARIABLE IS NOT DEFINED!: float object has no element 1"

}
Read vars_file 'vars/versions.yml'
Read vars_file 'vars/yum_logic.yml'

Kai Stian Olstad

unread,
Jul 20, 2018, 7:55:03 AM7/20/18
to ansible...@googlegroups.com
On 20.07.2018 13:29, Sreejith Sreejayan wrote:
> TASK [resweb : debug]
> ********************************************************************************************************************************
> task path: /home/tasks/main.yml:157
> ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
> "tomcat.resweb.version": "2.61.1"
> }
>
>
> TASK [resweb : debug]
> ********************************************************************************************************************************
> task path: /home/tasks/main.yml:158
> ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
> "tomcat.resweb.build": "d478a03"
> }
> Read vars_file 'vars/versions.yml'
> Read vars_file 'vars/yum_logic.yml'

So tomcat.resweb.version~ '-' ~tomcat.resweb.build would become
2.61.1-d478a03


> TASK [resweb : debug]
> ********************************************************************************************************************************
> task path: /home/tasks/main.yml:159
> ok: [lhqqa1rwbws01.qa1.allegiantair.com] => {
> "webpage.content": "<!doctype html>\n\n\n\n<html>\n<head>\n \n
> <script type=\"text/javascript\"
> src=\"js/jquery-1.7.1.min.js\"></script>\n <script
> type=\"text/javascript\">\n\n var resWebVersion =
> \"2.62.4-7ca3135
> (Build DateTime: 2018-07-03T05:53:23)\
> Read vars_file 'vars/versions.yml'
> Read vars_file 'vars/yum_logic.yml'

And 2.61.1-d478a03 is not in webpage.content


> On Fri, Jul 20, 2018 at 4:31 PM, Kai Stian Olstad <
> ansible-pr...@olstad.com> wrote:
>
>
>> On 20.07.2018 12:36, Sreejith Sreejayan wrote:
>>
>>> this is task code
>>> - name: Fail when the version does not match
>>> action: fail
>>> when: tomcat.resweb.version~ '-' ~tomcat.resweb.build not in
>>> webpage.content
>>> register: version_check

So this "Fail when the version does not match" is working since you
version string is not in content.

So what is the problem, since this code is working as it should?


--
Kai Stian Olstad

Kai Stian Olstad

unread,
Jul 20, 2018, 7:57:09 AM7/20/18
to ansible...@googlegroups.com
On 20.07.2018 13:49, Sreejith Sreejayan wrote:
> - debug: var="{{ tomcat.resweb.version~ '-' ~tomcat.resweb.build }}"

var takes a variable name not the content, you must use msg for that.

- debug: msg="{{ tomcat.resweb.version~ '-' ~tomcat.resweb.build }}"

--
Kai Stian Olstad

Brian Coca

unread,
Jul 20, 2018, 9:12:44 AM7/20/18
to Ansible Project
Looks like you are not leaving a space between the vars and operators,
~ should not be attached to the var name.
tomcat.resweb.version ~ '-' ~ tomcat.resweb.build

--
----------
Brian Coca

Kai Stian Olstad

unread,
Jul 20, 2018, 9:57:26 AM7/20/18
to ansible...@googlegroups.com
On 20.07.2018 15:11, Brian Coca wrote:
> Looks like you are not leaving a space between the vars and operators,
> ~ should not be attached to the var name.
> tomcat.resweb.version ~ '-' ~ tomcat.resweb.build

Actually, the spaces isn't needed at all, this will also work

Badraj Angirekula

unread,
Aug 27, 2018, 5:29:34 AM8/27/18
to ansible...@googlegroups.com
Hi all,
please help me.


Build ec2 instances with attaching multiple tags names :-
  For example- I have launched one ec2 instance with tag name "websever1" the next builds of ec2 instances should start with tag name webserver2 , webserver3 .... automatically.


Note: No two ec2 instances have same tag name.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3cccf0d0660b5bc6e7f533391bb205de%40olstad.com.

Kai Stian Olstad

unread,
Aug 27, 2018, 5:42:46 AM8/27/18
to Badraj Angirekula, ansible...@googlegroups.com
On Monday, 27 August 2018 11.29.15 CEST Badraj Angirekula wrote:
> Hi all,
> please help me.

Can you stop spamming the list?

This is the second time you hijack 5-10 threads that has nothing to do with your problem.


@admins, please ban this person from the list, at least but the person on permanently moderation.


--
Kai Stian Olstad


Reply all
Reply to author
Forward
0 new messages