ceph / cephmetrics

ceph metric collectors with collectd integration
GNU Lesser General Public License v3.0
64 stars 32 forks source link

Revert comparison "fix" from ansible-lint #246

Closed zmc closed 5 years ago

zmc commented 5 years ago

In d737083, we thought we were fixing something, but it turns out the comparison suggested will throw an error if container_name contains a dash (which it likely will). Revert the change and instruct ansible-lint to not complain about that error on that line.

Resolves: rhbz#1731919

Signed-off-by: Zack Cerza zack@redhat.com

zmc commented 5 years ago

The issue:

$ cat ./1731919.pb.yaml
---
- hosts: localhost
  gather_facts: false
  any_errors_fatal: true
  tasks:
    - name: Set container_name
      set_fact:
        container_name: "ceph-mgr-magna094"
    - name: Prefix the mgr command with a docker command
      set_fact:
        mgr_prefix: "docker exec {{ container_name }}"
      when: container_name

$ ansible-lint ./1731919.pb.yaml
$ ansible-playbook -v ./1731919.pb.yaml
PLAY [localhost] ***************************************************************

TASK [Set container_name] ******************************************************
ok: [localhost] => {"ansible_facts": {"container_name": "ceph-mgr-magna094"}, "changed": false}

TASK [Prefix the mgr command with a docker command] ****************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'container_name' failed. The error was: error while evaluating conditional (container_name): 'ceph' is undefined\n\nThe error appears to have been in '/Users/zack/dev/cephmetrics/1731919.pb.yaml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        container_name: \"ceph-mgr-magna094\"\n    - name: Prefix the mgr command with a docker command\n      ^ here\n"}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @/Users/zack/dev/cephmetrics/1731919.pb.retry

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

The fix:

$ cat ./1731919.pb.yaml
---
- hosts: localhost
  gather_facts: false
  any_errors_fatal: true
  tasks:
    - name: Set container_name
      set_fact:
        container_name: "ceph-mgr-magna094"
    - name: Prefix the mgr command with a docker command
      set_fact:
        mgr_prefix: "docker exec {{ container_name }}"
      when: container_name != ""

$ ansible-playbook -v ./1731919.pb.yaml
PLAY [localhost] ***************************************************************

TASK [Set container_name] ******************************************************
ok: [localhost] => {"ansible_facts": {"container_name": "ceph-mgr-magna094"}, "changed": false}

TASK [Prefix the mgr command with a docker command] ****************************
ok: [localhost] => {"ansible_facts": {"mgr_prefix": "docker exec ceph-mgr-magna094"}, "changed": false}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0