Improved way to scale in a salt sink

I have a template problem Jinja2

and this problem breaks a single line into multiple lines when it comes to writing state

or anything in salt

[my specific case relates to trying to write a list of machines one by one, in a list, not just a very long one line].

What I am trying to say is that I want to achieve this:

nodegroups:
  - group: 'L@adsdasdadas' +
            'dasdasdasdas'
             .............->imagine 10.000 names coming here
             'adsasdasddsa'

      

Compared to the approach I need to do now:

nodegroups:
  - group: 'L@adsdasdadas,dasdsadasdsa,dasdsadasdsa,......,asdqwe'

      

Is there a better way to do this? Is there a better way to handle thousands of machines?

You could tell grains

and I thought about it, but I was wondering if there is a better and elegant way to do this.

Any thoughts or opinions will help me a lot.

[Edit1]: I wrote a script that takes a list of hostnames and adds them to the main config file under the nodegroups section. Now it can work

+3


source to share


2 answers


Choosing a data source

I would recommend targeting with pillars because they are centrally managed from Master = convenient, not static custom grains (which are distro-configured on each Minion) = inconvenient - see comparison summary here .

Configuration file limitations

nodegroups

are specified in the Salt config file /etc/salt/master

, which is not a Jinja template (it is in pure YAML format). So there is no way for you to use Jinja to attach to external input with a list of strings.



Possible Solution

Why is the mention of the connection even mentioned? You can immediately flip the "split one line of a line into multiple lines" problem to a solution to use lists - no need to break (and if you need "one line of a line" somewhere, combining list items is easy).

In other words, you can define nodegroups

through a pillar (avoiding long lines like in your example). The pillars, in turn,turn out to be Jinja. Therefore, using the same Minions list defined elsewhere, you can generate a derived product in columns through Jinja (be it combined with a string or a list as it is). There is a trick that allows you to reuse the same external data in files with multiple columns .

+3


source


First of all, I would like to thank uvsmtid for a great idea. Sorry for the confusion created.

So what I did was create a pillar with the name of each minion [which happens to be id] and then in the state I did compare the value from that list with the actual id of the minion



{%for item in salt['pillar.get']('info') %}
  {%if grains['id'] == item %}
    something:
      cmd.run:
         - name: touch something

  {%endif%}
{%endfor%}

      

I hope this solution helps someone in the same way it did for me

+2


source







All Articles