Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Fix bug in conditional in tasks/main.yml #231

Closed

Conversation

danielelisi
Copy link

Closes #230

Summary

The object __node_exporter_current_version_output.stderr_lines is an empty list which causes the following bug in the tasks/main.yml/install.yml conditional. This bug happens only after provisioning the role for the first time.

TASK [cloudalchemy.node_exporter : Create the node_exporter group] ***********************************************************
fatal: [infra-mon-1]: FAILED! => 
  msg: |-
    The conditional check '( not __node_exporter_is_installed.stat.exists ) or ( __node_exporter_current_version_output.stderr_lines[0].split(" ")[2] != node_exporter_version ) or ( node_exporter_binary_local_dir | length > 0 )' failed. The error was: error while evaluating conditional (( not __node_exporter_is_installed.stat.exists ) or ( __node_exporter_current_version_output.stderr_lines[0].split(" ")[2] != node_exporter_version ) or ( node_exporter_binary_local_dir | length > 0 )): list object has no element 0
  
    The error appears to be in '/home/dan/.ansible/roles/cloudalchemy.node_exporter/tasks/install.yml': line 2, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.
  
    The offending line appears to be:
  
    ---
    - name: Create the node_exporter group
      ^ here

Content of the __node_exporter_current_version_output object

TASK [cloudalchemy.node_exporter : debug] ************************************************************************************
ok: [infra-mon-1] => 
  __node_exporter_current_version_output:
    changed: false
    cmd:
    - /usr/local/bin/node_exporter
    - --version
    delta: '0:00:00.003559'
    end: '2021-07-28 19:17:56.937383'
    failed: false
    rc: 0
    start: '2021-07-28 19:17:56.933824'
    stderr: ''
    stderr_lines: []
    stdout: |-
      node_exporter, version 1.2.0 (branch: HEAD, revision: 12968948aec1e2b216a2ecefc45cf3a50671aecb)
        build user:       root@6b17174de526
        build date:       20210715-16:35:54
        go version:       go1.16.6
        platform:         linux/amd64
    stdout_lines:
    - 'node_exporter, version 1.2.0 (branch: HEAD, revision: 12968948aec1e2b216a2ecefc45cf3a50671aecb)'
    - '  build user:       root@6b17174de526'
    - '  build date:       20210715-16:35:54'
    - '  go version:       go1.16.6'
    - '  platform:         linux/amd64'

The correct attribute to use to perform the conditional is stdout_lines.

Ansible Versions Tested

This bug is present on both Ansible 2.9.24 and Ansible 4.3.0

With this small fix I confirm that Ansible executes the playbook successfully without errors.

@danielelisi danielelisi changed the title Fix bug in conditional check in main.yml Fix bug in conditional in tasks/main.yml Jul 29, 2021
@danielelisi danielelisi mentioned this pull request Jul 29, 2021
@github-actions github-actions bot added the area/tasks Logic behind ansible role label Jul 29, 2021
@hungpr0
Copy link

hungpr0 commented Jul 29, 2021

Hello,

I have the same issue. stderr_lines is empty. It should be changed to stdout_lines

Thank you

@GeorgeGedox
Copy link

Pinging @paulfantom, could this be checked and pushed to a hotfix release? At the moment repeated deployments just break and I think this should be solved ASAP

@bmillemathias
Copy link

To be backward compatible the code should be check on stdout and stderr.

@danielelisi
Copy link
Author

To be backward compatible the code should be check on stdout and stderr.

This is being addressed in #233.

@danielelisi danielelisi closed this Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/tasks Logic behind ansible role
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when reinstall
4 participants