Author avatar


23 Jan, 2016

blogpost banner

SaltStack Vagrant Part 2

Last week we talked about creating a simple httpd service when we spin up our vagrant VM. This week I will continue to talk more about Salt.

Inside The Vagrant Virtual Machine

Salt run in /srv/ folder in our VM. Therefore our folder structure in virtual machine will look like this.

- /srv/
  - pillar/  # Unlike state tree, pillar data is only available for the targeted minion specified by the matcher type.
  - salt/  # All the configuration for the minion to run
- /etc/salt/
    - minion  #minion configuration
    - master  #master configuration

Running in Master-less vs Master mode

  • Master-less mode
salt-call --local state.highstate
  • Master mode: salt-minion need to accept the salt-key first
salt '*' state.highstate

For running vagrant, we use master-less mode, the different between master mode and master-less mode shouldn't be large.


To create user(s) base on pillar files, uninstall httpd and install nginx


  • Vagrantfile: mount the desired folder to your VM
config.vm.synced_folder "salt/root/", "/srv/salt/"
config.vm.synced_folder "salt/pillar/", "/srv/pillar/"
  • /srv/pillar/users/init.sls: Sensitive user data
        uid: 1000
        fullname: Heng Lim Ng
            - wheel
  • /srv/pillar/top.sls: Include any new pillar data here
    - users
  • /srv/salt/top.sls: the list of action we want to perform in env 'base', according to our objective
    - httpd.absent
    - user
    - nginx
  • /srv/salt/user/init.sls: make use of our pillar users
{% raw %}
{% for username, user in pillar.get('users', {}).items() %}
    - fullname: {{user.fullname}}
    - shell: /bin/bash
    - home: /home/{{username}}
    - groups: {{user.groups}}
{% endfor %}
{% endraw %}
  • /srv/salt/httpd/absent.sls: make sure we uninstalled the httpd that we have installed
httpd:               # ID declaration
  pkg.removed: []

  file.absent: []
  • /srv/salt/nginx/init.sls: yum search for nginx, if found, install nginx and enable it.
nginx:               # ID declaration
  pkg.installed: []
    - enable: True

To Be Continue

In this post I mainly described how to make use of pillar to manage our VM user, uninstalling and installing of services using yum packages. Stay tuned for the SaltStack Vagrant Part 3.