stefangweichinger/ansible-rclone

"Perform the install steps" task fails with Jinja2 < 2.11

Closed this issue · 13 comments

Hi !

I'm not sure it's an actual issue but I've just hit an error while trying to run your role in the kind of very simple playbook that you exemplify in the readme :

- hosts: all
  roles:
    - rclone

The error message is :

"The conditional check '(ansible_facts['ansible_local']['rclone']['installed'] is not true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version)' failed. The error was: template error while templating string: no test named 'true'. String: {% if (ansible_facts['ansible_local']['rclone']['installed'] is not true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version) %} True {% else %} False {% endif %}"

The test to blame is (ansible_facts['ansible_local']['rclone']['installed'] is not true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version) in main.yml :

when: (ansible_facts['ansible_local']['rclone']['installed'] is not true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version)

(... which was added in the latest commit)

I installed ansible ages ago via a pip install --user, and my installed version is 2.9.9, so I suspected a dependency problem.. and playing around a bit within a virtualenv, I realized the culprit was not ansible but Jinja2.

So here's the result of my fiddling around :

  • latest ansible-rclone + ansible >= 2.9.9 + Jinja2 >= 2.11 : ✔️
  • latest ansible-rclone + ansible >= 2.9.9 + Jinja2 < 2.11 : 🛑
  • previous version of ansible-rclone + ansible >= 2.9.9 + Jinja2 >= 2.10 : ✔️

(I guess the result will be the same with any version of ansible but I didn't bother to check)

The true test was added in Jinja2 version 2.11 indeed : https://jinja.palletsprojects.com/en/2.11.x/changelog/#version-2-11-0

Add new boolean, false, true, integer and float tests.

Again, I'm not sure how much of an issue it is considering Jinja2 version 2.11 is already more than one year old, and whether you can express that kind of dependency within ansible-galaxy, but I guess one might hit this issue when using old versions of ansible..

Cheers !

Great bug report, thanks.
Maybe we could skip the "is it installed already?" when we test for jinja2 >= 2.10 at the start?
Something like "improved logic only for up2date environments".

I already considered some pre-test tasks for some things like python-version etc

I guess ansible has a way to issue a warning in that case, so that seems like a fair idea indeed ! (even though it complicates the logic a bit)

But on this specific issue I'm now wondering whether the test (ansible_facts['ansible_local']['rclone']['installed'] is not true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version) could not simply be changed to ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version ?

I guess it would fail anyway if rclone is not installed..

(and that would entirely get rid of that issue with Jinja's "is true" test)

to consider, yes. and to test ;-)

A quick test in a local branch shows that your suggested test fails at the first run: ansible_facts['ansible_local']['rclone']['installed_version'] has no value/ is not defined yet.

TASK [ansible-rclone : Install the binary] *************************************
fatal: [instance]: FAILED! => {"msg": "The conditional check '(ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version)' failed. The error was: error while evaluating conditional ((ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version)): 'dict object' has no attribute 'rclone'\n\nThe error appears to be in '/home/sgw/projects/github/ansible-rclone/tasks/main.yml': line 46, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Install the binary\n  ^ here\n"}

In the former test that isn't a problem because ansible_facts['ansible_local']['rclone']['installed'] is not true at the first run.

look at #87 : new test statement, new handling of deploying the fact-checking script etc
Should work with older jinja2 as well.

For me the latest update still resulted in an error in the named line. I did some experiments and the following line works for me:

when: (ansible_facts.ansible_local.rclone is not defined) or (ansible_facts.ansible_local.rclone.installed != true) or (ansible_facts['ansible_local']['rclone']['installed_version'] != rclone_version)

@dsteinkopf could you show the error you got? My tests in molecule did not fail. What OS, etc?
thanks for suggesting the test, I have a look at it.

@dsteinkopf Just to talk about the same code: I think of merging #87 as all the tests succeeded. Please let me know what failed in your runs.

Oh, I thought #87 has already been released. My mistake. Sorry for the confusion.
#87 "looks" good to me, as is seems to address the problem I am having with the current galaxy version - I'll try it when it is released.

@dsteinkopf I merged #87 right now with commit 6b7153f

28 tests successful -> role was released to galaxy right now

New galaxy version works for me. Thank you very much.

Great to hear. Thanks for reporting and testing @dsteinkopf

@theenglishway If you also have no more issues with the current release, I will close here. Thanks.