Solved

Ansible lm_info devices by group

  • 1 February 2023
  • 11 replies
  • 75 views

  • Processor Participant
  • 3 replies

Hello All,


I am trying to achieve a similar result in Ansible using the LogicMonitor collections modules as I can get with the Rest API using python.

Using rest, I can do something like:
{{url}}/device/groups/{{group_id}}/devices
and I will get a list of all devices for the group specified in ‘group_id’.

I am trying to get the same result using the ansible lm_info module but no luck.
I am not trying to perform any action - just return the info.

I tried using full_path to narrow the device results down but I still get all devices instead of those associated with the group (this is not a collector group but a device group).  The group parameter is not supported for lm_info with a target: device but full_path is supposed to be supported.

I am reluctant to even post this question because I am probably missing something really simple 🙄 but …

Thanks in advance

icon

Best answer by JGJG 3 February 2023, 18:18

View original

11 replies

This should probably be posted in the Product Discussions category.


Apologies - is this not correct?  My first post on the new Community site.

I thought I came across this in the Community Feedback category. But I do see it under Product Discussions. My apologies.

Userlevel 7
Badge +17

I doubt you’re missing anything simple. My experience with the Ansible modules is that they are pretty lacking, not enough modules to control enough things to make it possible to control all of LM through Ansible. I wrote my own idempotent sync scripts using the SDK instead of going the Ansible route. 

Userlevel 4
Badge +9

I doubt you’re missing anything simple. My experience with the Ansible modules is that they are pretty lacking, not enough modules to control enough things to make it possible to control all of LM through Ansible. I wrote my own idempotent sync scripts using the SDK instead of going the Ansible route. 

We ended up doing the same as well. I had to write a python module, that emulates the SDK, but uses all the rest endpoints documented. We had to many inconsistent returns from the SDK to use it solely.

Userlevel 7
Badge +17

I’d be interested in the difficulties you ran into with the SDK. I’ve been able to use it except where the method doesn’t exist in the SDK for a specific endpoint in the API (like role groups).

Userlevel 4
Badge +9

At least prior, we had inconsistent data types being asked for in the “data” section for a post/put. Sometimes it seemed to want a string, sometimes it wanted an object/dict. We also had issues with returned data. Again this was a while back, but I swear sometimes we got camelcase, sometimes we got the underscored properties. Then we had the issue that you have, where things just weren’t there. Even if it wasn’t in the at the time v2 API, we could backwoods the v3 api via web developer tools in a browser and make things work. So we could easily just add it to the lm_rest function/class we built.

Userlevel 7
Badge +17

Yes, the difference between camel case and snake case is highly frustrating. I just got into the habit of converting all returned objects to dicts and converting all post/put objects into camel case (pretty easy function for that). 

Userlevel 4
Badge +9

Yeah, but at that point if I am already writing something to overcome something, plus having to divert from the SDK for a few other things, I may as roll my own code.

Userlevel 7
Badge +17

Agreed. I built up my own little library of functions to along with the SDK. 

Just to provide closure, I simply wrote a python script that takes parameters, passed in a value from a previous ansible step and registered the output from the python script to use in subsequent steps.

Not as streamlined as using straight Ansible, but it got the job done.

Thanks for all of the comments.

Have a great weekend

Reply