0

I'm trying to do proof of concept with Mongodb(sharding) and Id like to run a command every time I spin up a new cluster without having to add lines in all my sls files. My current init is as follows:

mongo Replica4:27000 /usr/lib/mongo/init_addshard.js:

cmd:

- run
- user: present

The word Replica4 is not templated id like to know a way I would be able to do so, that way when I spin up a new cluster I wouldn't have to touch anything in this file.

secure212
  • 228
  • 1
  • 3
  • 10

1 Answers1

1

Have a look at salt pillar. But before you do that check out my awful hack below, all in a single init.sls:

{% for environment in 'test','production','development' %}

  /etc/nginx/sites-available/{{ environment }}:
    file:
    - managed
    - source: salt://templates/nginx.conf.template
    - template: jinja
    - defaults:
      environment: {{ environment }}

  /etc/ssl/private/{{ environment }}.key.pem:
    file:
    - managed
    - source: salt://certs/{{ environment }}.key.pem

  /etc/ssl/certs/{{ environment }}.cert.pem:
    file:
    - managed
    - source: salt://certs/{{ environment }}.cert.pem

{% endfor %}

Mine is configuring the ssl key for nginx but you would just put in Replica4 in there, it will get expanded as environment. I just add environments as necessary and it sync it all up for me.

Yours might look something like:

 {% for environment in 'Replica4','Replica5', %}
    mongo {{ environment }}:27000 /usr/lib/mongo/init_addshard.js:

    cmd:

    - run
    - user: present

  {% endfor %}
gm3dmo
  • 9,632
  • 1
  • 40
  • 35