serve files

So we created a state file called apache.sls, as you may be aware, this includes some conf files, and if you modify these confs, apache must be reloaded to pickup the changes. Fortunately this is all pretty easy to automate with saltstack. We can keep one copy of the conf on the salt server that is pushed out to all minions that include the apache.sls.

Rename apache.sls to apache/init.sls

We call for apache in /srv/salt/top.sls, this looks for either a file named /srv/salt/apache.sls or /srv/salt/apache/init.sls. Since we will want to include additional things for apache, lets move it into the latter.

mkdir /srv/salt/apache
mv /srv/salt/apache.sls /srv/salt/apache/init.sls

You don’t need to do this, but as your number of state files grows, and you wish to include conf and other files, as well as additional states related to apache, it’s a good idea to organize things like this.

Serve httpd.conf from salt

In order for saltstack to serve files, we want to copy them into the relevant folder under /srv/salt. We’ll create a files directory under apache to keep files separate from state files.

mkdir /srv/salt/apache/files/
cp /etc/httpd/conf/httpd.conf /srv/salt/apache/files/

Modify apache state file to include httpd.conf

We now want to modify /srv/salt/apache/init.sls to include the conf file from saltstack. We also will want to tell the apache service to watch for changes to this file so it knows to reload appropriately.

We will want to add the following to the apache state file:

vi /srv/salt/apache/init.sls
    - name: httpd
    - name: httpd
# ------- below is new ------------------------
# ------- you can delete these comment lines --
      file: /etc/httpd/conf/httpd.conf
    - name: /etc/httpd/conf/httpd.conf
    - user: root
    - group: root
    - mode: 644
    - require:
      - pkg: httpd

Now if we modify /srv/salt/apache/files/httpd.conf, and run salt-call state.highstate on a minion that includes apache, or salt-call state.sls apache on any minion, it will pull the updated httpd.conf from the salt-master and reload the service appropriately.