Search code examples
rsyncsalt-project

Issues with rsync.synchronized in SaltStack Not Syncing Directory Content


I'm trying to use rsync.synchronized in SaltStack to sync a directory from master to a minion. Here's the SLS configuration I've used:

sync_pyenv:
  rsync.synchronized:
    - source: /home/user/test/
    - force: True

Executing salt 'test01' state.sls sync_files saltenv=dev results in the following error:

rsync: change_dir "/home/user/test" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23)

After ensuring the test directory exists on test01 and tweaking the SLS to include - prepare: True, the state runs successfully but doesn't sync the contents of /home/user/test/. The output indicates a successful run but shows "total size is 0".

I also tried adding - name: /home/user/test/ to the SLS, but it didn't resolve the issue. The directory and its contents are not being synced to the minion. I want to sync the test directory and its files without moving it to the Salt file_roots. What could be the issue here?


Solution

  • You have not specified a remote server for either the source or target. Nor have you specified a target directory. Thus it is running this command on test01:

    rsync --archive --force /home/user/test/ sync_pyenv
    

    The correct state would be:

    sync_pyenv:
      rsync.synchronized:
        - name: /home/user/test/
        - source: mysaltmaster:/home/user/test/
        - prepare: true
    

    You will still need to have set up SSH access for root from the minion to the master for this to work.

    If the source files are on the master, you should probably mount them on the fileserver (i.e. with file_roots) and use file.recurse:

    sync_pyenv:
      file.recurse:
        - name: /home/user/test/
        - source: salt://test_data/pyenv
    

    Or, recreate the pyenv using states to set it up from scratch, rather than copying from a random user's home directory.