f5devcentral / ansible-role-f5_atc_deploy_declaration

Ansible role used to deploy declaratives to F5 Automated Tool Chain services: AS3, DO, and TS
Apache License 2.0
7 stars 11 forks source link

Check as3 declaration fails with PATCH into a POST with BIG-IQ #27

Closed rjouhann closed 3 years ago

rjouhann commented 4 years ago

Hello,

I have a playbook where I am sending an AS3 app service using PATCH via a POST and the role is failing at check as3 declaration. The problem is when using AS3 with BIG-IQ, the direct PATCH to update an AS3 app service isn't allowed so user need to do a POST with "action": "patch".

The role needs to make sure it takes this use case in consideration when doing the checks.

Example playbook:

    tasks:
      - name: ATC POST all JSON under /ansible/as3/{{ as3dir }}
        include_role:
          name: f5devcentral.atc_deploy
        vars:
          atc_service: AS3
          atc_method: POST
          atc_declaration_file: "{{ item }}"
          atc_delay: 15
          atc_retries: 30
        loop: "{{ query('fileglob', '/ansible/as3/{{ as3dir }}/*as3*.json') | sort }}"
        register: atc_AS3_status

Example AS3 declaration:

{
    "class": "AS3",
    "action": "patch",
    "patchBody": [
        {
            "class": "ADC",
            "target": {
                "address": "10.192.75.183"
            },
            "op": "add",
            "path": "/boston/dns",
            "value": {
                "class": "Application",
                "dnsMain": {
                    "class": "GSLB_Domain",
                    "pools": [
                        {
                            "use": "/boston/dns/GSLB_Pool"
                        }
                    ],
                    "enabled": true,
                    "domainName": "airports.example.com",
                    "resourceRecordType": "A"
                },
                "template": "generic",
                "GSLB_Pool": {
                    "class": "GSLB_Pool",
                    "members": [
                        {
                            "server": {
                                "bigip": "/Common/boston"
                            },
                            "virtualServer": "/boston/MyWebApp217http/serviceMain"
                        },
                        {
                            "server": {
                                "bigip": "/Common/seattle"
                            },
                            "virtualServer": "/seattle/MyWebApp218http/serviceMain"
                        }
                    ],
                    "monitors": [
                        {
                            "use": "/boston/dns/GSLB_Monitor"
                        }
                    ],
                    "lbModeFallback": "return-to-dns",
                    "lbModeAlternate": "round-robin",
                    "lbModePreferred": "round-robin",
                    "resourceRecordType": "A"
                },
                "GSLB_Monitor": {
                    "send": "GET / HTTP/1.0",
                    "class": "GSLB_Monitor",
                    "receive": "HTTP/1.1 200 OK",
                    "monitorType": "https"
                }
            }
        }
    ]
}

Error message:

TASK [f5devcentral.atc_deploy : check as3 declaration and include teem data if needed] ***
task path: /root/.ansible/roles/f5devcentral.atc_deploy/tasks/main.yaml:77
<10.192.75.185> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.192.75.185> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible/tmp `"&& mkdir "` echo /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705 `" && echo ansible-tmp-1599677352.6649008-727-120354626744705="` echo /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705 `" ) && sleep 0'
Using module file /root/.ansible/roles/f5devcentral.atc_deploy/library/teem_check.py
<10.192.75.185> PUT /root/.ansible/tmp/ansible-local-1ex1b8b3n/tmpsyeklt_3 TO /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py
<10.192.75.185> EXEC /bin/sh -c 'chmod u+x /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/ /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py && sleep 0'
<10.192.75.185> EXEC /bin/sh -c '/usr/bin/python3 /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py && sleep 0'
<10.192.75.185> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py", line 102, in <module>
    _ansiballz_main()
  File "/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.teem_check', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.8/runpy.py", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py", line 63, in <module>
  File "/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py", line 50, in main
  File "/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py", line 12, in process_json
KeyError: 'declaration'
fatal: [cm-1.sjc2.lab.f5net.com]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/tmp/.ansible/tmp/ansible-tmp-1599677352.6649008-727-120354626744705/AnsiballZ_teem_check.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.teem_check', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 206, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py\", line 63, in <module>\n  File \"/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py\", line 50, in main\n  File \"/tmp/ansible_teem_check_payload_9dxgpiss/ansible_teem_check_payload.zip/ansible/modules/teem_check.py\", line 12, in process_json\nKeyError: 'declaration'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
focrensh commented 3 years ago

Thanks, validating that this behavior works in future integrations.