# Node creation from Ansible (or other) template?

**URL:** <https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598>\
**Category:** Developing Nodes\
**Created:** [6 July 2020 13:27 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598 "2020-07-06T13:27:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2020 13:27 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/1 "2020-07-06T13:27:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 July 2020 13:49 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/2 "2020-07-06T13:49:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [6 July 2020 14:07 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/3 "2020-07-06T14:07:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2020 21:02 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/4 "2020-07-06T21:02:50Z")

</div>

> [@dceejay](#):
>
> see the node-red-nodegen project

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2020 21:08 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/5 "2020-07-06T21:08:20Z")

</div>

> [@Nodi.Rubrum](#):
>
> As much as I have played with Ansible, I still don't love Ansible.

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 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 July 2020 21:43 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/6 "2020-07-06T21:43:37Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 July 2020 21:49 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/7 "2020-07-06T21:49:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 July 2020 21:53 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/8 "2020-07-06T21:53:18Z")

</div>

Presumably like the json for a subflows dialog definition ?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 July 2020 21:57 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/9 "2020-07-06T21:57:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [6 July 2020 22:24 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/10 "2020-07-06T22:24:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2020 09:46 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/11 "2020-07-07T09:46:28Z")

</div>

> [@knolleary](#):
>
> Yes, if it works there, no reason not to reuse it elsewhere.

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2020 09:48 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/12 "2020-07-07T09:48:23Z")

</div>

> [@Nodi.Rubrum](#):
>
> Ansible definitely has a learning curve

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 July 2020 09:50 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/13 "2020-07-07T09:50:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [7 July 2020 09:59 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/14 "2020-07-07T09:59:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2020 10:42 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/15 "2020-07-07T10:42:46Z")

</div>

> [@dceejay](#):
>
> if the yaml followed that structure then it would be good re-use.

Is that structure documented somewhere?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 July 2020 10:49 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/16 "2020-07-07T10:49:23Z")

</div>

> [@Colin](#):
>
> Is that structure documented somewhere?

This is the original design note for the subflow property UI feature - [designs/designs/subflow-property-ui at master · node-red/designs · GitHub](https://github.com/node-red/designs/tree/master/designs/subflow-property-ui)

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2020 11:10 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/17 "2020-07-07T11:10:44Z")

</div>

OK, thanks, will take a look.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 September 2020 11:22 UTC](https://discourse.nodered.org/t/node-creation-from-ansible-or-other-template/29598/18 "2020-09-05T11:22:09Z")

</div>

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