title: How do I pull change records from ServiceNow for a specific system?
body: <p>I'm trying to automate patching and need to find a way to pull change records from ServiceNow for specific servers and find out if a change window is open for that server.  </p>
  
  <p>I tried doing this in Ansible but so far I've had no luck. I'm wondering if there is a better way to do this? Maybe through Python or just something simple with using curl and bash? I've heard of some people having luck with rest APIs but I know very little about it.  </p>
  
  <p>Here is an example of my playbook using the snow_record module:</p>
  
  <pre><code> - hosts: localhost
    connection: local
    gather_facts: no
    ignore_errors: True
    tasks:
    - name: Grab a user record
      snow_record:
        username: testuser
        password: somepass
        instance: myinstance
        state: present
        number: CHG9999
        table: change_request
        lookup_field: cmdb_ci.name=someservername
  </code></pre>
  
  <p>Error output:</p>
  
  <pre><code>  The full traceback is:
      Traceback (most recent call last):
        File "/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py", line 113, in &lt;module&gt;
          _ansiballz_main()
        File "/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py", line 105, in _ansiballz_main
          invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
        File "/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py", line 48, in invoke_module
          imp.load_module('__main__', mod, module, MOD_DESC)
        File "/tmp/ansible_snow_record_payload_0p5jn8/__main__.py", line 332, in &lt;module&gt;
        File "/tmp/ansible_snow_record_payload_0p5jn8/__main__.py", line 328, in main
        File "/tmp/ansible_snow_record_payload_0p5jn8/__main__.py", line 317, in run_module
      AttributeError: 'module' object has no attribute 'UnexpectedResponse'
  
      fatal: [localhost]: FAILED! =&gt; {
          "changed": false, 
          "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py\", line 113, in &lt;module&gt;\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1553017980.16-56687342300902/AnsiballZ_snow_record.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_snow_record_payload_0p5jn8/__main__.py\", line 332, in &lt;module&gt;\n  File \"/tmp/ansible_snow_record_payload_0p5jn8/__main__.py\", line 328, in main\n  File \"/tmp/ansible_snow_record_payload_0p5jn8/__main__.py\", line 317, in run_module\nAttributeError: 'module' object has no attribute 'UnexpectedResponse'\n", 
          "module_stdout": "", 
          "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
          "rc": 1
  </code></pre>
  
  <p>I tried snow_record_find. A module I found <a href="https://github.com/garbled1/ansible_modules" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Playbook:</p>
  
  <pre><code>- hosts: mytest
    tasks:
    - name: Grab a user record
      snow_record_find:
        username: testuser
        password: somepass
        instance: someinstance
        #state: present
        #number: null??
        table: change_request
        query:
          AND:
            equals:
              active: "True"
              type: "standard"
              u_change_stage: "80"
            contains:
              u_template: "MY-Template"
  </code></pre>
  
  <p>Error output from that:</p>
  
  <pre><code>fatal: []: FAILED! =&gt; {
      "changed": false, 
      "module_stderr": "Shared connection to  closed.\r\n", 
      "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1553019300.21-10858374496170/AnsiballZ_snow_record_find.py\", line 113, in &lt;module&gt;\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1553019300.21-10858374496170/AnsiballZ_snow_record_find.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1553019300.21-10858374496170/AnsiballZ_snow_record_find.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_snow_record_find_payload_j9P62r/__main__.py\", line 260, in &lt;module&gt;\r\n  File \"/tmp/ansible_snow_record_find_payload_j9P62r/__main__.py\", line 257, in main\r\n  File \"/tmp/ansible_snow_record_find_payload_j9P62r/__main__.py\", line 249, in run_module\r\n  File \"/usr/lib/python2.7/site-packages/pysnow/legacy_request.py\", line 91, in _all_inner\r\n    yield self._get_content(response)\r\n  File \"/usr/lib/python2.7/site-packages/pysnow/legacy_request.py\", line 332, in _get_content\r\n    server_error['summary'], server_error['details']\r\npysnow.legacy_exceptions.UnexpectedResponse: Unexpected HTTP GET response code. Expected 200, got 401\r\n", 
      "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
  </code></pre>