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.

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 %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.