CiscoDevNet/ansible-meraki

meraki_alert - Default/Alert Destination: email is not optional after initial push

DerrickTJ opened this issue · 4 comments

meraki_alert's alerts: and default_destinations will successfully push configuration without a emails: on the initial deployment. If you rerun the task though, it will fail. This prevents you from reusing the playbook.

You shouldn't need an email on every alert because we expect the default destination to take care of this. Secondly, we do not use emails, we use webhooks for these aka httpServerIds

These two tasks can obviously be one task but broken up to show the errors easier that is happens to both sections.

    - name: Apply Default Settings for Alerts
      cisco.meraki.meraki_alert:
        auth_key: abc12345
        org_name: YourOrg
        net_name: MyNet
        state: present
        default_destinations:
          all_admins: no
          snmp: no
          #emails: "djohnson@company.com"
          http_server_ids: "xxxx" #webhook id

    - name: Apply Alerts
      cisco.meraki.meraki_alert:
        auth_key: abc12345
        org_name: YourOrg
        net_name: MyNet
        state: present
        alerts:
          - alert_type: "settingsChanged"
            enabled: yes
            alert_destinations:
              all_admins: no
              snmp: no
              #emails: "djohnson@company.com"
      delegate_to: localhost

Error when it is ran a second time:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: object of type 'NoneType' has no len()
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/djohnson/.ansible/tmp/ansible-tmp-1673463346.012788-91328-183734641598206/AnsiballZ_meraki_alert.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/djohnson/.ansible/tmp/ansible-tmp-1673463346.012788-91328-183734641598206/AnsiballZ_meraki_alert.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/djohnson/.ansible/tmp/ansible-tmp-1673463346.012788-91328-183734641598206/AnsiballZ_meraki_alert.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.cisco.meraki.plugins.modules.meraki_alert', init_globals=dict(_module_fqn='ansible_collections.cisco.meraki.plugins.modules.meraki_alert', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.py\", line 356, in <module>\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.py\", line 333, in main\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/module_utils/network/meraki/meraki.py\", line 185, in is_update_required\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/module_utils/network/meraki/meraki.py\", line 176, in is_update_required\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/module_utils/network/meraki/meraki.py\", line 185, in is_update_required\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/module_utils/network/meraki/meraki.py\", line 185, in is_update_required\n  File \"/var/folders/80/qxqt__d92fz5dknpxl46xk9n02zpz9/T/ansible_cisco.meraki.meraki_alert_payload_p6erowjc/ansible_cisco.meraki.meraki_alert_payload.zip/ansible_collections/cisco/meraki/plugins/module_utils/network/meraki/meraki.py\", line 171, in is_update_required\nTypeError: object of type 'NoneType' has no len()\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Adding the email address to the alert destination and the module works as it should. Email address is only optional during initial deployment.

I'm going to guess that it is because emails does not have a default of [] like http_server_ids does maybe. Doesn't explain why it works on the initial push though.

My guess seems to be correct. PR Submitted. Appears to fix it in my tests for both default_destinations and alerts

@DerrickTJ I have a PR (#420) open for fixing this problem. It's a pretty big rewrite of the payload assembly code so please give it a test.

K. I'll test that out on Monday. Have a good weekend!

Going to close this PR out.

Oops, thought this was my PR I did. haha