Node creation from Ansible (or other) template?

It has occurred to me that one could write an Ansible role which would take a yaml file defining the requirements of a node, including the name, field names and types, and so on, and it would automatically generate skeleton js and html files for the node. Would that be a worthwhile thing to do? Alternatively I expect there are other template expansion applications which would do something similar.

Perhaps someone has already done something like that.

The difficult bit would be writing it so that one could amend the yaml file and run it again and it would update the bits it has control over, without messing up other stuff added. Perhaps that would not be possible, I don't know.

see the node-red-nodegen project that can take swagger api definitions, or WoT definitions etc as a starter.

As much as I have played with Ansible, I still don't love Ansible. I can't put my finger on it, what explicitly bugs me about Ansible, just don't love the tool. I actually like Foreman better, but Foreman is an OS deployment engine, not application deployment engine. Maybe it is because Foreman is more UI friendly? Now if Ansible had a wire editor like node-red? That would be cool.

I did look at nodegen some while ago and decided at that time that it didn't do what I had hoped, but perhaps I missed something. I will take another look.

I do love it. I think that sometimes a tool seems to match the way one's brain works and it just seems right. Meanwhile another person can't get on with it at all. Different brain pathways or something I expect. Not that I don't get annoyed with it sometimes, but it is not uncommon to get annoyed with things you love occasionally :slight_smile:

I'm sure it won't do what you actually want.. But is a good example of taking a yaml definition and creating nodes from it... I suspect what you want is even more general than this and so would probably be even more complex.. But worth a look see to see how they do it..

Slight off topic, but I do think there is an interesting idea around a more declarative approach to auto generating a node's edit dialog.

It wouldn't cater for all scenarios by any means, but if a node's config is a relatively simple set of key/value pairs, it ought to be possible to generate the editor dialog just from its definition with a bit more meta data added.

Something for a rainy day.

Presumably like the json for a subflows dialog definition ?

Yes, if it works there, no reason not to reuse it elsewhere.

Ansible definitely has a learning curve to structure things the way it wants.

It wouldn't want to be json based though, would it? I would have thought it would want to be yaml or something similar that is easier to enter manually and can contain comments.

Yes, and it isn't really the right tool for this, but a template expansion tool such that that contained in Ansible would do the job I think. I haven't so far managed to find a standalone tool that does that though.

For what I have in mind, the meta-data would be provided as additional properties to the values in the node's defaults property in the html file. So it would be JavaScript/JSON in there, being the lingua franca.

This isn't intended as a replacement for what you are discussing - someone could still create a YAML -> node html generator.

It is just an observation that for simple nodes, it would save a lot of boilerplate HTML from being written.

yes - yaml <-> json can be achieved :-).. the point being that we already can define subflow ui elements via the subflow config editor and that produces a json structure already - so some of the technology you need is known... so if the yaml followed that structure then it would be good re-use.

Is that structure documented somewhere?

This is the original design note for the subflow property UI feature -

But things do evolve between an original design proposal and what eventually ships. So there may be slight discrepancies. We need to go through and revalidate the information in there.

OK, thanks, will take a look.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.