How to sync every file under /srv/salt from Salt Master to Salt Syndic

116 Views Asked by At

Ran across a situation where I needed to keep the files sync'd from my Salt Master to my Syndic. I searched online but couldn't really find any real solution other than the usual, "use a shared filesystem, rsync them over, etc).

Those solutions may be an option for others but for my environment, that would not work and needed a solution within Salt to do this.

After searching and testing, I modified the closest solution I was able to find and came up with the following that keeps /srv/salt sync'd on the Syndic to what's on the Master:

{% for file in salt['cp.list_master']() %}
/srv/salt/{{ file }}:
  file.managed:
    - name: /srv/salt/{{ file }}
    - source: salt://{{ file }}
    - user: salt
    - group: salt
    - mode: 640
    - makedirs: True
{% endfor %}

Hope this helps others!

1

There are 1 best solutions below

7
OrangeDog On

If you can set up the credentials, an rsync state will probably have better performance:

/srv/salt:
  rsync.synchronized:
    - source: salt:/srv/salt
    - delete: true
    - force: true

You might also consider a different fileserver backend that can be more easily shared.


Unfortunately, this doesn't work. It looks like a bug in the source parser.

/srv/salt:
  file.recurse:
    - source: salt://
    - clean: true
    - keep_symlinks: true