dj-wasabi / ansible-zabbix-agent

Installing and maintaining zabbix-agent for RedHat/Debian/Ubuntu/Windows/Suse.
https://galaxy.ansible.com/dj-wasabi/zabbix-agent
MIT License
327 stars 249 forks source link

s/agent_interfaces/zabbix_agent_interfaces ? #95

Closed paszczus closed 7 years ago

paszczus commented 7 years ago

Hello, Since version 1.0 all vars should start from "zabbix_". I see that in this line there is agentinterfaces without zabbix prefix. Is this ok? It won't work for now:

https://github.com/dj-wasabi/ansible-zabbix-agent/blob/b812ba036060a05d84d16d804a61bb96b90abdd8/tasks/main.yml#L185

` agent_interfaces:

An error:

fatal: [10.59.146.63]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'agent_interfaces' is undefined\n\nThe error appears to have been in '/etc/ansible/roles/dj-wasabi.zabbix-agent/tasks/main.yml': line 173, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: \"Create a new host or update an existing host's info\"\n ^ here\n"}

paszczus commented 7 years ago

Ahh now i see that this is duplicate of #94

dj-wasabi commented 7 years ago

I created a PR for this.

paszczus commented 7 years ago

Thanks, i have merged your changes to local role but there is still an error:

FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: [{u'ip': u'{{ zabbix_agent_ip }}', u'useip': u'{{ zabbix_useuip }}', u'dns': u'{{ ansible_fqdn }}', u'main': 1, u'type': 1, u'port': u'{{ zabbix_agent_listenport }}'}]: 'zabbix_agent_ip' is undefined\n\nThe error appears to have been in '/etc/ansible/roles/dj-wasabi.zabbix-agent/tasks/main.yml': line 173, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: \"Create a new host or update an existing host's info\"\n ^ here\n"}

dj-wasabi commented 7 years ago

Hi @paszczus

I created another pr and before I'll merge it, will this help you: https://github.com/dj-wasabi/ansible-zabbix-agent/pull/97 ?

I need to think of a way to properly test these kinds of tasks with Molecule. Scenario's are introduced with Molecule V2, but V2 is not there yet it seems.

dsteinkopf commented 7 years ago

My results are: I had to patch my files in /etc/ansible/roles/dj-wasabi.zabbix-agent/ with

  1. your patch above
  2. some more forgotten variable renames.

Now, everything seems to work for me.

Here are my changes (including yours):

--- /etc/ansible/roles/dj-wasabi.zabbix-agent/defaults/main.yml.orig    2017-08-31 11:44:46.000000000 +0200
+++ /etc/ansible/roles/dj-wasabi.zabbix-agent/defaults/main.yml 2017-09-01 05:42:06.289257485 +0200
@@ -43,9 +43,9 @@
   - type: 1
     main: 1
     useip: "{{ zabbix_useuip }}"
-    ip: "{{ agent_ip }}"
+    ip: "{{ zabbix_agent_ip }}"
     dns: "{{ ansible_fqdn }}"
-    port: "{{ agent_listenport }}"
+    port: "{{ zabbix_agent_listenport }}"

 # Zabbix configuration variables
 zabbix_agent_pidfile: /var/run/zabbix/zabbix_agentd.pid
--- /etc/ansible/roles/dj-wasabi.zabbix-agent/tasks/main.yml.orig       2017-08-31 11:44:46.000000000 +0200
+++ /etc/ansible/roles/dj-wasabi.zabbix-agent/tasks/main.yml    2017-09-01 05:39:12.525123113 +0200
@@ -49,6 +49,13 @@
     - config
     - service

+- name: "Set default ip address for zabbix_agent_ip"
+  set_fact:
+    zabbix_agent_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4'].address }}"
+  when:
+    - zabbix_agent_ip is not defined
+    - "'ansible_default_ipv4' in hostvars[inventory_hostname]"
+
 - name: "Fail invalid specified agent_listeninterface"
   fail:
     msg: "The specified network interface does not exist"
@@ -176,13 +183,13 @@
     server_url: "{{ zabbix_url }}"
     login_user: "{{ zabbix_api_user }}"
     login_password: "{{ zabbix_api_pass }}"
-    host_name: "{{ agent_hostname }}"
+    host_name: "{{ zabbix_agent_hostname }}"
     host_groups: "{{ zabbix_host_groups }}"
     link_templates: "{{ zabbix_link_templates }}"
     status: "{{ zabbix_host_status }}"
     state: "{{ zabbix_create_host }}"
     proxy: "{{ zabbix_proxy }}"
-    interfaces: "{{ agent_interfaces }}"
+    interfaces: "{{ zabbix_agent_interfaces }}"
   when:
     - zabbix_api_create_hosts
   become: no
dsteinkopf commented 7 years ago

BTW. Don't forget to update variable names in README.md.

paszczus commented 7 years ago

@dj-wasabi yes, works fine for me now, thank you!

dj-wasabi commented 7 years ago

@dsteinkopf Merged the PR and updated documentation with the correct variable names (Forgot to add the prefix zabbix_).