ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
322 stars 284 forks source link

zabbix action appears always with changed #243

Closed jessequinn closed 3 years ago

jessequinn commented 4 years ago
SUMMARY

Using the zabbix_action to add an auto-registration action always shows changed.

ISSUE TYPE
COMPONENT NAME

zabbix_action v1.0.0

ANSIBLE VERSION
ansible 2.9.14
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, Jul 20 2020, 23:11:29) [GCC 9.3.0]
CONFIGURATION
DEFAULT_TRANSPORT(/etc/ansible/ansible.cfg) = ssh
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT / Zabbix Version

Zabbix Web/Server 5.0.4

STEPS TO REPRODUCE
- name: Create auto registration action
  local_action:
    module: zabbix_action
    server_url: "{{ url }}"
    validate_certs: no
    login_user: "{{ username }}"
    login_password: "{{password }}"
    name: "{{ auto_registration_item.name }}"
    event_source: "auto_registration"
    state: present
    status: enabled
    esc_period: "60"
    conditions:
      - type: "host_metadata"
        operator: "like"
        value: "{{ auto_registration_item.host_metadata }}"
        formulaid: A
    formula: A
    operations:
      - type: add_host
      - type: add_to_host_group
        host_groups: "{{ auto_registration_item.hostgroup }}"
      - type: link_to_template
        templates: "{{ auto_registration_item.templates }}"
    timeout: 60
EXPECTED RESULTS

As the items already exist from running the ansible script. I expect the state to show OK.

ok: [...] => (item={...})
ACTUAL RESULTS

First item in loop appears with OK all subsequent items show changed: vvvv output minus some client related info. Again. all auto-registration actions already exist. If i comment out the first item all zabbix_actions show changed.

changed: [...] => (item={...}) => {
    "ansible_loop_var": "auto_registration_item",
    "auto_registration_item": {
        "host_metadata": "...",
        "hostgroup": [
            "...",
            "..."
        ],
        "name": "Auto register hosts through proxy ... for ...",
        "templates": [
            "Template ASM-Oracle",
            "Template Backup RMAN",
            "Template Oracle ODBC",
            "Template OS Linux"
        ]
    },
    "changed": true,
    "invocation": {
        "module_args": {
            "acknowledge_default_message": "",
            "acknowledge_default_subject": "",
            "acknowledge_operations": [],
            "conditions": [
                {
                    "formulaid": "A",
                    "operator": "like",
                    "type": "host_metadata",
                    "value": "...",
                    "value2": null
                }
            ],
            "default_message": "",
            "default_subject": "",
            "esc_period": "60",
            "eval_type": null,
            "event_source": "auto_registration",
            "formula": "A",
            "http_login_password": null,
            "http_login_user": null,
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_user": "ansible",
            "name": "Auto register hosts through proxy ... for ...",
            "operations": [
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": null,
                    "esc_step_from": 1,
                    "esc_step_to": 1,
                    "execute_on": null,
                    "host_groups": null,
                    "inventory": null,
                    "media_type": null,
                    "message": null,
                    "operation_condition": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": null,
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "templates": null,
                    "type": "add_host",
                    "username": null
                },
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": null,
                    "esc_step_from": 1,
                    "esc_step_to": 1,
                    "execute_on": null,
                    "host_groups": [
                        "...",
                        "..."
                    ],
                    "inventory": null,
                    "media_type": null,
                    "message": null,
                    "operation_condition": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": null,
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "templates": null,
                    "type": "add_to_host_group",
                    "username": null
                },
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": null,
                    "esc_step_from": 1,
                    "esc_step_to": 1,
                    "execute_on": null,
                    "host_groups": null,
                    "inventory": null,
                    "media_type": null,
                    "message": null,
                    "operation_condition": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": null,
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "templates": [
                        "Template ASM-Oracle",
                        "Template Backup RMAN",
                        "Template Oracle ODBC",
                        "Template OS Linux"
                    ],
                    "type": "link_to_template",
                    "username": null
                }
            ],
            "pause_in_maintenance": true,
            "recovery_default_message": "",
            "recovery_default_subject": "",
            "recovery_operations": [],
            "server_url": "...",
            "state": "present",
            "status": "enabled",
            "timeout": 60,
            "validate_certs": false
        }
    },
    "msg": "Action Updated: Auto register hosts through proxy ... for ..., ID: {'actionids': [35]}"
}
D3DeFi commented 3 years ago

Thanks for opening this issue @jessequinn .

For the completeness, below is my testing playbook. I've tried to mirror what you wrote as closely as possible:

- hosts: localhost
  vars:
    autoregitems:
      - name: Auto register hosts 
        hostgroup:
        - Linux servers
        templates:
        - Template OS Linux by Zabbix agent
        host_metadata: "meta"
      - name: Auto register hosts 2
        hostgroup:
        - Zabbix servers
        templates:
        - Template OS Linux by Zabbix agent
        host_metadata: "meta2"
  tasks:
    - name: Create auto registration action
      local_action:
        module: zabbix_action
        server_url: "http://localhost:8080/"
        validate_certs: no
        login_user: "Admin"
        login_password: "zabbix"
        name: "{{ auto_registration_item.name }}"
        event_source: "auto_registration"
        state: present
        status: enabled
        esc_period: "60"
        conditions:
          - type: "host_metadata"
            operator: "like"
            value: "{{ auto_registration_item.host_metadata }}"
            formulaid: A
        formula: A
        operations:
          - type: add_host
          - type: add_to_host_group
            host_groups: "{{ auto_registration_item.hostgroup }}"
          - type: link_to_template
            templates: "{{ auto_registration_item.templates }}"
        timeout: 60
      loop: '{{  autoregitems }}'
      loop_control:
        loop_var: auto_registration_item

My observations:

Can you please confirm that my testing playbook isn't that far off from what are you trying to do? Also can you please test if this also works correctly for you with ansible 2.10 if possible? I am pretty sure there have been some changes to the zabbix_action module that got rejected from 2.9 as ansible transitioned to the 2.10, hence the difference in behavior.

jessequinn commented 3 years ago

@D3DeFi looks about right. i think the killer is just make sure you run against several servers. But i am wondering if is it an issue directly related to templates. if a template uses a marco, that could change, would alter the state?

D3DeFi commented 3 years ago

@D3DeFi looks about right. i think the killer is just make sure you run against several servers. But i am wondering if is it an issue directly related to templates. if a template uses a marco, that could change, would alter the state?

Sorry for a delayed response. I don't think that macro value can change whole template from the perspective of ansible unless it is the template itself that is defining a macro (or rather a default value for macro).

Anyway, are you still hitting this problems even with community.zabbix:1.2.0?

D3DeFi commented 3 years ago

issue dormant, solution offered, please feel free to reopen if you are still experiencing this as there was no response for more than half a year now