geerlingguy / ansible-role-fluentd

Ansible role - Fluentd (td-agent)
https://galaxy.ansible.com/geerlingguy/fluentd
MIT License
34 stars 28 forks source link

'<' not supported between instances of 'AnsibleUnsafeText' and 'int' #12

Closed jmsierra closed 3 years ago

jmsierra commented 3 years ago

Hi there,

I've come across the following error when deploying:

TASK [geerlingguy.fluentd : Determine fluent-gem executable location for td-agent < v4] *************************************************************************************************************************
fatal: [dc2-frontend1]: FAILED! => {"msg": "The conditional check 'fluentd_version < 4' failed. The error was: Unexpected templating type error occurred on ({% if fluentd_version < 4 %} True {% else %} False {% endif %}): '<' not supported between instances of 'AnsibleUnsafeText' and 'int'\n\nThe error appears to be in '/home/jmsierra/.ansible/roles/geerlingguy.fluentd/tasks/main.yml': line 22, 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: Determine fluent-gem executable location for td-agent < v4\n  ^ here\n"}
fatal: [dc2-frontend2]: FAILED! => {"msg": "The conditional check 'fluentd_version < 4' failed. The error was: Unexpected templating type error occurred on ({% if fluentd_version < 4 %} True {% else %} False {% endif %}): '<' not supported between instances of 'AnsibleUnsafeText' and 'int'\n\nThe error appears to be in '/home/jmsierra/.ansible/roles/geerlingguy.fluentd/tasks/main.yml': line 22, 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: Determine fluent-gem executable location for td-agent < v4\n  ^ here\n"}

Ansible environment:

jmsierra@*******:~/workspace/devcycle-ansible/****$ ansible --version
ansible [core 2.11.1] 
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/jmsierra/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jmsierra/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/jmsierra/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/jmsierra/.local/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True

I believe it can be fixed by adding an explicit casting to int in tasks/main.yml:

- name: Determine fluent-gem executable location for td-agent < v4
  set_fact:
    fluent_gem_executable: /opt/td-agent/embedded/bin/fluent-gem
  when: (fluentd_version | int) < 4

- name: Determine fluent-gem executable location for td-agent v4
  set_fact:
    fluent_gem_executable: /opt/td-agent/bin/fluent-gem
  when: (fluentd_version | int) >= 4

PS: Thank you so much for your amazing contributions!