geerlingguy / ansible-role-fluentd

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

Error when comparing fluentd_version variable #13

Closed jmsierra closed 3 years ago

jmsierra commented 3 years ago

If fluentd_version variable is defined programatically depending on something else. For example:

fluentd_version: "{{ (3 if ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7' else 4) | int }}"

It's always casted as string, making the following check in tasks/main.yml to fail and always consider it as >=4

- 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 < 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 >= 4

However the installation is done as version 3, raising the following error:

TASK [geerlingguy.fluentd : Determine fluent-gem executable location for td-agent < v4] *************************************************************************************************************************
skipping: [dc1-elastic1]
skipping: [dc1-elastic2]

TASK [geerlingguy.fluentd : Determine fluent-gem executable location for td-agent v4] ***************************************************************************************************************************
ok: [dc1-elastic1]
ok: [dc1-elastic2]

TASK [geerlingguy.fluentd : Ensure Fluentd plugins are installed.] **********************************************************************************************************************************************
failed: [dc1-elastic2] (item=fluent-plugin-elasticsearch) => {"ansible_loop_var": "item", "changed": false, "cmd": "/opt/td-agent/bin/fluent-gem query -n '^fluent-plugin-elasticsearch$'", "item": "fluent-plugin-elasticsearch", "msg": "[Errno 2] No such file or directory", "rc": 2}
failed: [dc1-elastic1] (item=fluent-plugin-elasticsearch) => {"ansible_loop_var": "item", "changed": false, "cmd": "/opt/td-agent/bin/fluent-gem query -n '^fluent-plugin-elasticsearch$'", "item": "fluent-plugin-elasticsearch", "msg": "[Errno 2] No such file or directory", "rc": 2}

I'd say it could be changed for the following to force the casting to int before making the comparison:

- 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
stale[bot] commented 3 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 3 years ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.