Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zabbix_template: fails without template_groups, cryptic error #50834

Closed
richlv opened this issue Jan 12, 2019 · 4 comments · Fixed by #51222
Closed

zabbix_template: fails without template_groups, cryptic error #50834

richlv opened this issue Jan 12, 2019 · 4 comments · Fixed by #51222
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. zabbix Zabbix community

Comments

@richlv
Copy link
Contributor

richlv commented Jan 12, 2019

SUMMARY

The zabbix_template module lists template_groups as being optional, but when leaving them off import fails.
Additionally, an invalid request is sent to the API, and the resulting error is very cryptic.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

zabbix_template

ANSIBLE VERSION
ansible 2.6.8
  config file = /opt/ansible/config/ansible-config-cdevops0.cert.motive.com.cfg
  configured module search path = [u'/home/username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.6.6 (r266:84292, Aug  9 2016, 06:11:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

Also tested with zabbix_template from devel.

CONFIGURATION
DEFAULT_FORKS(/opt/ansible/config/ansible-config-hostname.cfg) = 100
OS / ENVIRONMENT

Tested against Zabbix 4.0.3.

STEPS TO REPRODUCE

Attempt to import any template without specifying template_groups; the actual template contents do not matter.

Actually the file contents do not mater at all - a garbage file would be simply ignored.

- name: Import Zabbix templates
  zabbix_template:
    server_url: "http://localhost/zabbix/"
    login_user: zbx_api_cli
    login_password: "{{zbx_api_cli_password}}"
    template_name: "Some template"
    template_json: "{{ lookup('file', 'files/zabbix-templates/zbx_template-Some_template.json') }}"
    state: present
EXPECTED RESULTS

Template is imported.

ACTUAL RESULTS

Several problems:

  • Import fails (see the error below).
  • Actual file contents are ignored and a mostly empty request is sent to the Zabbix API (see the API response below).
failed: [target.host] (item=HS Template App App) => {"changed": false, "item": "HS Template App App", "module_stderr": "Shared connection to howl.incert.motive.com closed.
", "module_stdout": "Traceback (most recent call last):
  File \"/tmp/ansible_LjKS35/ansible_module_zabbix_template.py\", line 555, in <module>
    main()
  File \"/tmp/ansible_LjKS35/ansible_module_zabbix_template.py\", line 540, in main
    child_template_ids, macros)
  File \"/tmp/ansible_LjKS35/ansible_module_zabbix_template.py\", line 270, in add_template
    'macros': macros})
  File \"/usr/lib/python2.7/site-packages/zabbix_api.py\", line 329, in method
    return self.universal(\"%s.%s\" % (self.data[\"prefix\"], name), opts[0])
  File \"/usr/lib/python2.7/site-packages/zabbix_api.py\", line 79, in wrapper
    return self.do_request(self.json_obj(method, opts))['result']
  File \"/usr/lib/python2.7/site-packages/zabbix_api.py\", line 336, in do_request
    return self.parent.do_request(req)
  File \"/usr/lib/python2.7/site-packages/zabbix_api.py\", line 287, in do_request
    raise ZabbixAPIException(msg, jobj['error']['code'])
zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., Template \"HS Template App App\" cannot be without host group. while sending {\"params\": {\"templates\": null, \"macros\": null, \"host\": \"HS Template App App\", \"groups\": null}, \"jsonrpc\": \"2.0\", \"method\": \"template.create\", \"auth\": \"e3034a2d681979b79499b067c18b30a0\", \"id\": 2}', -32602)
", "msg": "MODULE FAILURE", "rc": 1}
@ansibot
Copy link
Contributor

ansibot commented Jan 12, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Jan 12, 2019

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Jan 12, 2019
@D3DeFi
Copy link
Contributor

D3DeFi commented Jan 21, 2019

Thank you for pointing this bug out. I did some quick testing and found a problem within add_template() method.

If you look at the method's logic you will see that it first creates 'empty' template via template.create API call and then tries to overwrite it via configuration.import.

I am a bit worried that there may have been some reason for this particular approach and changing it may break something, but we won't find that out without original module author anyways :/. My guess is that there was some bug in older zabbix server versions.

I will try to find some spare time to reimplement this logic. I believe that changing this would allow us to implement #50833 as well.

@richlv
Copy link
Contributor Author

richlv commented Jan 21, 2019

Thank you for looking into this. Hard to say what could have been the reasons, and this also explains other behaviour I was seeing - an empty host created when the actual import failed. That would also go away with this issue resolved.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jan 21, 2019
@dagwieers dagwieers added the zabbix Zabbix community label Jan 28, 2019
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. zabbix Zabbix community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants