ansible-collections / servicenow.itsm

Ansible Collection for ServiceNow ITSM
GNU General Public License v3.0
94 stars 81 forks source link

Incident_mapping not working as expected #396

Closed markatdxb closed 2 months ago

markatdxb commented 2 months ago
SUMMARY

Incident_mapping, close_code is in dictionary format, when set, the playbook is failing. There is no example to follow up the correct formatting

ISSUE TYPE
COMPONENT NAME

incident

ANSIBLE VERSION
2.16.9
COLLECTION VERSION
2.6.1
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
- name: SNOW - Close incident
  servicenow.itsm.incident:
    instance:
      host: https://{{ snow_instance }}.service-now.com
      username: "{{ user }}"
      password: "{{ password }}"
    sys_id: "{{ sn_rec_sys_id }}"
    state: closed
    close_notes: Incident is closed as all Content library templates are consistent in all sites
    incident_mapping:
      close_code: Solved (Permanently)
EXPECTED RESULTS

close the incident

ACTUAL RESULTS
{
    "msg": "argument 'close_code' is of type <class 'str'> found in 'incident_mapping'. and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value",
    "invocation": {
        "module_args": {
            "instance": {
                "host": "https://xxxx.service-now.com",
                "username": "user",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "api_path": "api/now",
                "validate_certs": true,
                "grant_type": null,
                "client_id": null,
                "client_secret": null,
                "custom_headers": null,
                "refresh_token": null,
                "access_token": null,
                "timeout": null
            },
            "sys_id": "01234567891234567812345678",
            "state": "closed",
            "close_notes": "Incident is closed as all Content library templates are consistent in all sites",
            "incident_mapping": {
                "close_code": "Solved (Permanently)",
                "state": null,
                "hold_reason": null,
                "impact": null,
                "urgency": null
            },
            "number": null,
            "attachments": null,
            "hold_reason": null,
            "caller": null,
            "short_description": null,
            "description": null,
            "impact": null,
            "urgency": null,
            "close_code": null,
            "other": null
        }
    },
markatdxb commented 2 months ago

@tupyy - can you pls check above comment - is that some sort of hack of your repo ? i havent even tried to download the file

tupyy commented 2 months ago

@markatdxb Please take a look at intergration tests. https://github.com/ansible-collections/servicenow.itsm/tree/main/tests/integration/targets/itsm_incident_with_mapping/tasks

tupyy commented 2 months ago

@markatdxb Please take a look at intergration tests.

@tupyy - can you pls check above comment - is that some sort of hack of your repo ? i havent even tried to download the file

I don't know what it is and there's no way that I download something like that. @seeronline If you have a solution please paste the diff. don't use zip.

markatdxb commented 2 months ago

@

@markatdxb Please take a look at intergration tests.

@tupyy - can you pls check above comment - is that some sort of hack of your repo ? i havent even tried to download the file

I don't know what it is and there's no way that I download something like that. @seeronline If you have a solution please paste the diff. don't use zip.

seems that some sort of a bot - looking at the seeronline user. you might want to report it to github owners

markatdxb commented 2 months ago

@markatdxb Please take a look at intergration tests. https://github.com/ansible-collections/servicenow.itsm/tree/main/tests/integration/targets/itsm_incident_with_mapping/tasks

so i correctly understand that integration test file

may code should look like this ?

- name: SNOW - Close incident
  servicenow.itsm.incident:
    instance:
      host: https://{{ snow_instance }}.service-now.com
      username: "{{ user }}"
      password: "{{ password }}"
    sys_id: "{{ sn_rec_sys_id }}"
    state: closed
    close_notes: Incident is closed as all Content library templates are consistent in all sites
    incident_mapping:
      close_code: 
        solved_unknown: Solved (Permanently) 
tupyy commented 2 months ago

yes

markatdxb commented 2 months ago

ok tested that with following code - still getting error

- name: SNOW - Close incident
  servicenow.itsm.incident:
    instance:
      host: https://{{ snow_instance }}.service-now.com
      username: "{{ user }}"
      password: "{{ password }}"
    sys_id: "{{ snow_find.record[0].sys_id }}"
    state: closed
    close_notes: Incident is closed as all Content library templates are consistent in all sites
    incident_mapping:
      close_code: 
        solved_unknown: Solved (Permanently)
"msg": "Missing required parameters close_code",
    "invocation": {
        "module_args": {
            "instance": {
                "host": "https://server.service-now.com",
                "username": "user",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "api_path": "api/now",
                "validate_certs": true,
                "grant_type": null,
                "client_id": null,
                "client_secret": null,
                "custom_headers": null,
                "refresh_token": null,
                "access_token": null,
                "timeout": null
            },
            "sys_id": "012345678901234567890123456789",
            "state": "closed",
            "close_notes": "Incident is closed as all Content library templates are consistent in all sites",
            "incident_mapping": {
                "close_code": {
                    "solved_unknown": "Solved (Permanently)"
                },
                "state": null,
                "hold_reason": null,
                "impact": null,
                "urgency": null
            },
            "number": null,
            "attachments": null,
            "hold_reason": null,
            "caller": null,
            "short_description": null,
            "description": null,
            "impact": null,
            "urgency": null,
            "close_code": null,
            "other": null
        }
    },
    "warnings": [
        "Encountered unknown value  while mapping field close_code."
    ],
tupyy commented 2 months ago

It seems we do have a bug in there. It will need more investigation but you're right. it does not work as intended. But there's a workaround for you:

tupyy commented 2 months ago

@markatdxb Hello. After a better look at the code, you need to specify the close_code in your task. The module will pick up the right value from the mapping that you provided.

- name: SNOW - Close incident
  servicenow.itsm.incident:
    instance:
      host: https://{{ snow_instance }}.service-now.com
      username: "{{ user }}"
      password: "{{ password }}"
    sys_id: "{{ snow_find.record[0].sys_id }}"
    state: closed
    close_notes: Incident is closed as all Content library templates are consistent in all sites
    close_code: solved_unknown
    incident_mapping:
      close_code: 
        solved_unknown: Solved (Permanently)

On the other hand, if you don't add the choices to SNow as I've shown above, the close_code will be ignored by ServiceNow.

I'm closing this one because it's not a bug