praiseHellRaiseDale
praiseHellRaiseDale

Reputation: 2270

How do I get schedule.present to work in saltstack?

I want to have a directory on my salt-master, that keep synced to the windows 7 minion I have running. I tried using schedule.present, but I've had very little luck. I'm not sure what my problem with that is, but I also think that this may not be the best way to accomplish my task.

Here's what my environment looks like:

salt-master

OS: CentOS7

salt version: 2016.3.0


salt-minion

OS: Ubuntu 14.04

salt version: 2016.3.0


Here's my current configuration:

init.sls

syncFiles:
  schedule.present:
    - function: /home/user/directory
    - seconds: 30
    - splay: 10

/home/user/directory:
  file.recurse:
    - source: salt://source/directory/

When I run this, everything returns successfully, and mirrordirectory runs the first time as expected, but no times in the future.

The debug output from the minion is this.

[INFO  ] Invalid function: mirrordirectory in scheduled job syncFiles.

I'm guessing I need to put the function on the minion, but I can't find that anywhere in the documentation.

If there's a way to do this without putting a function on the minion, I'm interested in knowing what it is, but I'd like to at least learn how to run schedules in saltsatck.

Any help is appreciated.


Side Note

Eventually, this is going to be a Windows 7 minion, instead of ubuntu, I'm just trying to get this to work first.


UPDATE 1

Here's what I've tried based on the answer below (and it's still not working).

/srv/salt/mirrordirectory/init.sls

syncFiles:
  schedule.present:
    - function: state.sls
- job_args:
  - testfile
- seconds: 30
- splay: 10

/srv/salt/testfile.sls

/tmp/foo:
  file.recurse:
    - source: salt://files

/srv/salt/top.sls

base:
  '*':
    - mirrordirectory

/srv/salt/files

This directory contains files to be synced

The master returns all success:

myminion:
----------
          ID: syncFiles
    Function: schedule.present
      Result: True
     Comment: Job syncFiles in correct state
     Started: 16:18:22.290216
    Duration: 140.989 ms
     Changes:   

Summary for myminion
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1

The debug on the minion shows a problem:

[DEBUG   ] Sending event - data = {'fun_args': ['testfile'], 'jid': 'req', 'return': ["No matching sls found for 'testfile' in env 'base'"], 'retcode': 1, 'success': True, 'schedule': 'syncFiles', 'cmd': '_return', 'pid': 24448, '_stamp': '2016-06-15T21:19:57.928894', 'fun': 'state.sls', 'id': 'myminion'}
[DEBUG   ] Handling event tag '__schedule_return'
[INFO    ] Returning information for job: req

This line seems to be the problem ["No matching sls found for 'testfile' in env 'base'"]. Any idea why it can't find the file?


UPDATE 2

/etc/salt/master

interface: 192.168.0.1
user: salt

Those are the only two lines in my master config file. I wanted to test running as a user other than root, and everything had been working fine after I changed some file permissions. Maybe that's the issue...maybe I missed something.

Upvotes: 1

Views: 2199

Answers (1)

alexK
alexK

Reputation: 953

The function for schedule.present must be a salt function. In your case probably what you want to do is to use state.sls. Here is an example similar to what you have that worked for me:

foo.sls

syncFiles:
  schedule.present:
    - function: state.sls
    - job_args:
      - testfile
    - seconds: 30
    - splay: 10

testfile.sls

/tmp/foo:
  file.recurse:
    - source: salt://files

top.sls

base:
  '*':
    - foo

So, what happens here is - top.sls applies foo.sls to a minion. foo.sls in turn makes a minion apply testfile.sls every 30 seconds.

Hope this helps!

Upvotes: 3

Related Questions