Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

now inventory plugin cannot return ip_address field #357

Closed
miyuk opened this issue May 7, 2024 · 5 comments
Closed

now inventory plugin cannot return ip_address field #357

miyuk opened this issue May 7, 2024 · 5 comments
Assignees

Comments

@miyuk
Copy link

miyuk commented May 7, 2024

SUMMARY

When using now inventory to get inventory from cmdb_ci_server, ip_addres is empty because ip_address is stored in other table(cmdb_ci_ip_address).

https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/configuration-management/concept/class-server.html#d707944e556

ISSUE TYPE
  • Bug Report
COMPONENT NAME

servicenow.itsm.now

ANSIBLE VERSION
ansible [core 2.16.6]
  config file = None
  configured module search path = ['/home/x/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/x/.local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/x/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/x/.local/bin/ansible
  python version = 3.11.7 (main, Jan 22 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3.0.1)] (/usr/bin/python3.11)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
# /home/x/.ansible/collections/ansible_collections
Collection                               Version
---------------------------------------- -------
servicenow.itsm                          2.5.0
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

Oracle Linux 9.3

STEPS TO REPRODUCE
  1. Add server info to cmdb_ci_server
  2. Add ip_address and network_adapter and related to server
  3. Run ansible-inventory -i now.yml --list
# now.yml
---
plugin: servicenow.itsm.now
strict: true
instance:
  host: https://devxxxxx.service-now.com/
  grant_type: password
  username: xxxxx
  password: xxxxx
table: cmdb_ci_server

inventory_hostname_source: name
columns:
  - name
  - sys_id
  - fqdn
  - serial_number
  - ip_address
  - os
  - os_version
EXPECTED RESULTS

return empty ip_address

ACTUAL RESULTS

return not empty ip_address


@tupyy tupyy self-assigned this May 15, 2024
@tupyy
Copy link
Contributor

tupyy commented May 15, 2024

Hello.
I can't reproduce your problem.
This is working fine for me:

- name: Test constructed options
  hosts: localhost
  gather_facts: false

  tasks:
    - block:
        - name: Create imaginary VMs
          servicenow.itsm.configuration_item:
            name: server_{{ item }}
            sys_class_name: cmdb_ci_linux_server
            ip_address: 10.1.0.{{ item }}
          loop: "{{ range(1, 3) | list }}"
          register: vms

        - name: Reload inventory
          ansible.builtin.meta: refresh_inventory

        - ansible.builtin.assert: 
            that: 
              - item is defined
              - item is string
              - item | length > 0
          loop: "{{ vms | community.general.json_query('results[*].record.ip_address') }}"

      always:
        - name: Delete VMs
          servicenow.itsm.configuration_item:
            state: absent
            sys_id: "{{ item.record.sys_id }}"
          loop: "{{ vms.results }}"
          loop_control:
            label: "{{ item.record.name }}"

Result:

PLAY [Test constructed options] **********************************************************************************************

TASK [Create imaginary VMs] **************************************************************************************************
ok: [localhost] => (item=1)
ok: [localhost] => (item=2)

TASK [Reload inventory] ******************************************************************************************************

TASK [ansible.builtin.assert] ************************************************************************************************
ok: [localhost] => (item=10.1.0.1) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "10.1.0.1",
    "msg": "All assertions passed"
}
ok: [localhost] => (item=10.1.0.2) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "10.1.0.2",
    "msg": "All assertions passed"
}

TASK [Delete VMs] ************************************************************************************************************
changed: [localhost] => (item=server_1)
changed: [localhost] => (item=server_2)

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@miyuk
Copy link
Author

miyuk commented May 23, 2024

@tupyy
In ServiceNow document, ip_address field couldn't use at cmdb_ci_server.

Do not store the MAC address or the IP address in the Server [cmdb_ci_server] class.​

https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/configuration-management/concept/class-server.html#d707944e556

so, this inventory plugin have to reference other table(cmdb_ci_ip_address or cmdb_ci_network_adapter)

@tupyy
Copy link
Contributor

tupyy commented Jun 3, 2024

To do what the doc says the plugin needs to make another request to snow.
The worst-case scenario is when the inventory makes 3 requests: one for the table itself, one for referenced columns, and one for ip_address. This will slow even more the inventory which is already slow. Some users wait 45min for 15k hosts with no reference column request.

Therefore, out of the box, we'll not be able to support what you need. First of all, it needs to be backward compatibility (implementing this will break existing inventory for a lot of users) and second, we need to make the inventory usable (users cannot wait 30min for 10-15k hosts).

What I propose to you is to make a reference of ip_address to the table of you choice and use that in your inventory.
This means you need to change your data model.

@miyuk
Copy link
Author

miyuk commented Jun 4, 2024

I understood that.
current now inventory couldn't use in latest SNOW to get address.

We will develop custom script to get address.

thanks.

@tupyy
Copy link
Contributor

tupyy commented Jun 4, 2024

Thank you. I'll go ahead and close this issue now. Please reopen if you think it is relevant.

@tupyy tupyy closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants