ansible-collections / servicenow.itsm

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

Feat: Add support for lists sourced from columns #390

Open Shkrelic opened 1 month ago

Shkrelic commented 1 month ago
SUMMARY

When pulling records with duplicate key/hostnames, lists should be used in appropriate fields, rather than strings.

For example, when using the u_flattned_ci_rel table to find application/server mappings, u_child can be utilized as the inventory_hostname_source. This creates a problem which overwrites the field with the last query results. I did not open this as a bug as it seems like it is probably working as intended.

ISSUE TYPE
COMPONENT NAME

inventory plugin - servicenow.itsm.now

ADDITIONAL INFORMATION

This feature would be extremely useful to map application relationships and required support groups when making OS level changes to the Runs on:runs host running/serving an application/DB.

For example;

prd-server01 runs apache webserver prd-server01 runs tomcat webserver

inventory should create the following when pulling from this table using u_child as the inventory_hostname_source:

Expected:

prd-server01:
  applications: [ 
    {
    u_parent_application.name: "apache-webserver",
    u_parent_support_group.name: "ITSM-Operations-Websupport"
    },
    {
    u_parent_application.name: "tomcat-webserver",
    u_parent_support_group.name: "ITSM-Development-Websupport"
    },
  u_child_environment: "Production",
  etc vars...

Actual:

prd-server01:
  u_parent_application: "tomcat-webserver",
  u_parent_support_group: "ITSM-Development-Websupport",
  u_child_environment: "Production",
  etc vars...

EXAMPLE
plugin: servicenow.itsm.now
table: u_flattened_ci_rel
query:
  - u_active: "= true"
  - u_level: "!= L4"
inventory_hostname_source: u_child
instance:
  timeout: 300
columns:
  - u_parent
  - u_parent.support_group
  - u_parent_application
  - u_child.ip_address
  - u_child.install_status
  - u_child.operational_status
  - u_type
  - u_ci_type
  - sys_id
  - u_level
tupyy commented 1 week ago

@Shkrelic Hello. Thanks for the issue. I'm working on it but I have problems mocking your data model.

I've created a new table u_flattened_ci_rel with:

Is this layout the same as yours?

As a result, I have:

ansible-inventory -i now.yml --list
{
    "_meta": {
        "hostvars": {
            "i101": {
                "sys_id": "f9fc8d0633a8d210392d0e570e5c7bff",
                "u_child_ip_address": "10.1.0.101",
                "u_child_name": "i101",
                "u_level": "1",
                "u_parent": "tomcat_pxgnodig",
                "u_parent_name": "tomcat_pxgnodig",
                "u_parent_support_group": "Application Development",
                "u_type": "active"
            }
        }
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    },
    "ungrouped": {
        "hosts": [
            "i101"
        ]
    }
}

i101 should have 2 tomcats but got only one. I think this confirms the issue.

tupyy commented 1 week ago

Could you paste the whole output please?