Skip to content

Commit

Permalink
feature/no_dot_var - Replace "." in columns name to "_"
Browse files Browse the repository at this point in the history
  • Loading branch information
ecchong committed Mar 25, 2024
1 parent 5b5681c commit 09e142e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/no_dot_var.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- replace "." in reference field colums to "_"
2 changes: 1 addition & 1 deletion plugins/inventory/now.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def set_hostvars(self, host, record, columns):
)

for k in columns:
self.inventory.set_variable(host, k, record[k])
self.inventory.set_variable(host, k.replace('.','_'), record[k])

def fill_constructed(
self,
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/targets/inventory/files/no_dot_var.now.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
plugin: servicenow.itsm.now
table: cmdb_ci_server
strict: false

instance:
timeout: 1200

columns:
- location.name
- support_group.name

compose:
ansible_host: ip_address

sysparm_query: nameSTARTSWITHmy-vm-
...
44 changes: 44 additions & 0 deletions tests/integration/targets/inventory/playbooks/no_dot_var.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Test sysparm_limit option
hosts: localhost
gather_facts: false

tasks:
- block:
- name: Create imaginary VMs
servicenow.itsm.configuration_item:
name: my-vm-{{ item }}
sys_class_name: cmdb_ci_server
ip_address: 10.1.0.{{ item }}
other:
state: "{{ (item % 4 == 0) | ansible.builtin.ternary('on', 'off') }}"
guest_os_fullname: "{{ (item < 105) | ansible.builtin.ternary('OS0', 'OS1') }}"
loop: "{{ range(100, 110) }}"
register: vms

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

- ansible.builtin.debug:
var: groups

- ansible.builtin.debug:
var: hostvars["my-vm-100"]

- name: Verify the replaced variable names exist
ansible.builtin.assert:
that:
- groups["all"] | length == 10
- hostvars["my-vm-100"].location_name is defined
- hostvars["my-vm-100"].support_group_name is defined
- hostvars["my-vm-104"].location_name is defined
- hostvars["my-vm-104"].support_group_name is defined

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 }}"

0 comments on commit 09e142e

Please sign in to comment.