Need guidelines in salt structure organisation

34 views
Skip to first unread message

Plup

unread,
Aug 20, 2016, 12:39:54 PM8/20/16
to Salt-users
Hi guys,

I'm new to salt and I'm migrating from Ansible.
I try to organise my configs and I would like to have your opinion about the best salty way to do it.

I want to deploy apps with salt.

Each app is defined by a set of parameters :
myapp1:
    domain
: myapp1.example.com
    repository
: github.com/plup/myapp1

myapp2
:
    domain
: myapp2.example.com
    repository
: github.com/plup/myapp2

And each app has one profile (django, nodejs,...) which is configured in a state file profile/init.sls (simplified for the example) :
deploy {{ app }}:
  cmd
.run:
   
- name: 'echo I\'m deploying {{ app }}'
  file
.managed:
   
- name: '/tmp/{{ app }}.conf'
   
- source: 'salt://{{ slspath }}/tmpl.j2'
   
- template: jinja

With the template file profile/tmpl.j2 :
You will find the source code of {{ app }} at {{ repository }}

 And now I would like to deploy my applications with something like that:
salt '*' state.apply myapp1
salt '*' state.apply myapp2

I tried to use macro defining app parameters in myappX.sls files and calling the macro fonction from profile/init.sls. But it doesn't work with the variables in the template file.

I tried to use pillar to configure apps but as the entrypoint of deploy command is the profile/init.sls I didn't find a way to pass app specific parameters to the state file.

And now, I'm stuck. Any idea would by appreciated.

James Young

unread,
Aug 24, 2016, 5:30:13 PM8/24/16
to Salt-users
You actually can us pillars for this using pillar.get(), look at the below example: 

Pillar setup: 

/srv/pillar/top.sls:

base:
   
"*":
     
- myApp

/srv/pillar/myApp.sls:
myapp1:
    domain
: myapp1.example.com
    repository
: github.com/plup/myapp1

Using this data in a state: 

echo the domain is, {{ pillar.get('myapp1').get('domain') }}:
   cmd
.run

So long as the pillar is applied, your state will be able to utilize its information at execution time. Hope that helps!

Loren Gordon

unread,
Aug 24, 2016, 9:52:11 PM8/24/16
to Salt-users
Another trick, use the salt module for pillar, rather than the .get() dictionary function, and you can specify a key at any point in the dictionary more directly using a colon as a delim... i.e. `salt.pillar.get('myapp1:domain')` rather than `pillar.get('myapp1').get('domain')`...
Reply all
Reply to author
Forward
0 new messages