servicenow.itsm collection and ansible inventory plugin

Hello everyone. I have been working with the collection for ServiceNow and ansible for about a week or so and I’ve come across an issue I can’t seem to resolve. I’m using the ansible inventory plugin to get my inventory from cmdb. I would like to create groups for specific versions of the linux OS’s I have in my environment.

Unfortunately in CMDB we don’t capture the OS version either major or minor numbers in CMDB, But we do capture the uname -a which I can then parse out the major kernel version number I can can assume by that number which version of the OS it is.

The issue I have is I cannot seem to correct format the key so if the major number = “3” then the group name would be RHEL7 and major number =“4” would be RHEL8. The RHEL7 and RHEL8 are the group names I’m trying to build. But whatever I try won’t work.

Here is my existing code as it stands today for just RHEL7:

keyed_groups:

  • key: u_network_zone | replace(‘-’, ‘_’)
    trailing_separator: no
  • key: “{% if short_description.split(’ ‘)[2].split(’.')[0] == ‘3’ %}RHEL7{% endif %}”
    trailing_separator: no

I tried a few other way of approaching this but none of them work. Has anyone tried this or have any suggestions? By the way, this collection is from Redhat and not the collection from GITHUB or galaxy. I see they are a tad bit different. I’m using 1.4.0 in case that matters

Thanks!

Glen

Well I’m going to answer my own question because I found a work-around to this issue. While I wish there was an easier and less stupid way it works for me so I can keep on track with my project. Here is the snippet of code that works just in case someone else might have this same issue.

  • key: u_network_zone | replace(‘-’, ‘_’)
    separator: “”
  • key: os_version.split(‘.’)[0] | replace(‘7’, ‘RHEL7’) | replace(‘8’, ‘RHEL8’)
    separator: “”

I did find we do capture the os_version so I used that instead and just replaced the single digits with the string I wanted. To me it’s a hack but it’s a working hack for me.

Enjoy!

Glen