ansible / ansible-modules-extras

Ansible extra modules - these modules ship with ansible
948 stars 1.46k forks source link

zabbix_host fails if called to create/update a host when "force: false" #3466

Closed oncipriani closed 7 years ago

oncipriani commented 7 years ago
ISSUE TYPE
COMPONENT NAME

zabbix_host

ANSIBLE VERSION
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION

None

OS / ENVIRONMENT

N/A

SUMMARY

The module "zabbix_host" fails if called to create/update a host on Zabbix when "force: false".

STEPS TO REPRODUCE
  1. Make sure the host you are trying to create/update already exists on Zabbix server;
  2. Use the "zabbix_host" module with "force: false".
---
- name: register host on Zabbix server
  local_action:
    module: zabbix_host
    server_url: http://zabbix.example.com/zabbix
    login_user: ansible
    login_password: superSecret
    host_name: "{{ ansible_fqdn }}"
    host_groups:
      - Discovered hosts
    link_templates:
      - Template OS Linux
    status: disabled
    state: present
    force: false
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
        dns: "{{ ansible_fqdn }}"
        port: 10050
...
EXPECTED RESULTS

When trying to register a host that is already registered and with "force: false", I expected that the zabbix_host module would just return gracefuly with something like "failed: false" and "changed: false".

ACTUAL RESULTS

If the host already exists on Zabbix server, the playbook exits with a "MODULE FAILURE". If the host does not already exist, the playbook is executed correclty and the host is created as expected.

Here is the output of ansible-playbook with "-vvv":

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_1baBu5/ansible_module_zabbix_host.py", line 562, in <module>
    main()
  File "/tmp/ansible_1baBu5/ansible_module_zabbix_host.py", line 506, in main
    module.fail_json(changed=False, result="Host present, Can't update configuration without force")
  File "/tmp/ansible_1baBu5/ansible_modlib.zip/ansible/module_utils/basic.py", line 1807, in fail_json
AssertionError: implementation error -- msg to explain the error is required

fatal: [teste-rhel6 -> localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "invocation": {
        "module_name": "zabbix_host"
    },
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_1baBu5/ansible_module_zabbix_host.py\", line 562, in <module>\n    main()\n  File \"/tmp/ansible_1baBu5/ansible_module_zabbix_host.py\", line 506, in main\n    module.fail_json(changed=False, result=\"Host present, Can't update configuration without force\")\n  File \"/tmp/ansible_1baBu5/ansible_modlib.zip/ansible/module_utils/basic.py\", line 1807, in fail_json\nAssertionError: implementation error -- msg to explain the error is required\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE"
}
ansibot commented 7 years ago

@cove, @harrisongu, ping. This issue is waiting on your response. click here for bot help

ansibot commented 7 years ago

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

ansibot commented 7 years ago

This issue was migrated to https://github.com/ansible/ansible/issues/29413