diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f68ff34 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: python +python: + - '2.7' + +env: + global: + - BS_PIP_ALLOWED=1 + - BS_ECHO_DEBUG=1 + - SALT_ARGS="-l debug --local --retcode-passthrough --pillar-root=test/pillar --file-root=$PWD" + matrix: + - STATE=rsyncd + - STATE=rsyncd.config + +before_install: + - sudo apt-get update + - curl -L http://bootstrap.saltstack.org | sudo -E sh -s -- stable + +install: + - sudo mkdir -p /srv && sudo ln -sfn $PWD /srv/formula + # See what kind of travis box you're on to help with making your states + # compatible with travis + - sudo salt-call grains.items --local + +script: + - sudo salt-call state.show_sls $STATE $SALT_ARGS + - sudo salt-call state.sls $STATE $SALT_ARGS + + # For debugging purpose + - cat /etc/default/rsync + - test -f /etc/rsyncd.conf && cat /etc/rsyncd.conf || echo "No rsyncd.conf" + + # Idempotence check + - sudo salt-call state.sls $STATE $SALT_ARGS > /tmp/second + - cat /tmp/second + - bash -c '! grep -q "^Not Run:" /tmp/second' diff --git a/README.rst b/README.rst index acd1030..06322f1 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,6 @@ +.. image:: https://travis-ci.org/martinhoefling/rsyncd-formula.svg?branch=master + :target: https://travis-ci.org/martinhoefling/rsyncd-formula + ================ rsyncd-formula ================ @@ -18,9 +21,18 @@ Available states ``rsyncd`` ------------ -Installs the rsync package, and starts the rsyncd service. +Installs the rsync package, and starts the rsyncd service. Note: The rsyncd.conf has to be created manually / via another state. If the state of the config should also be managed via salt, the rsyncd.config state (which pulls rsyncd) should be used instead. ``rsyncd.config`` ------------ Configure the rsync daemon by writing an rsync.conf and rsync secrets (optional). + +Testing +======= + +As you can read in .travis.yml, testing is a matter of symlinking this +directory to /srv/formula (because we can't use relative paths in file_roots / +pillar_roots) and running:: + + salt-call state.show_highstate --local --retcode-passthrough --config-dir=test/etc diff --git a/rsyncd/init.sls b/rsyncd/init.sls index a57bc33..8d277c9 100644 --- a/rsyncd/init.sls +++ b/rsyncd/init.sls @@ -1,11 +1,23 @@ {% from "rsyncd/map.jinja" import rsyncd with context %} +rsyncd_conf_exists: + file.managed: + - name: {{ rsyncd.configfile }} + - contents: | + # This file is created by salt as a dummy, use the config state or override manually + pid file = /var/run/rsyncd.pid + use chroot = yes + read only = yes + - replace: false + rsync: pkg.installed: - name: {{ rsyncd.pkg }} service.running: - name: {{ rsyncd.service }} - enable: True + - require: + - file: rsyncd_conf_exists {% if grains.os_family == 'Debian' %} /etc/default/rsync: diff --git a/rsyncd/map.jinja b/rsyncd/map.jinja index d16bd9b..14e30ff 100644 --- a/rsyncd/map.jinja +++ b/rsyncd/map.jinja @@ -5,4 +5,10 @@ 'configfile': '/etc/rsyncd.conf', 'secretsfile': '/etc/rsyncd.secrets' }, + 'Arch': { + 'pkg': 'rsync', + 'service': 'rsyncd', + 'configfile': '/etc/rsyncd.conf', + 'secretsfile': '/etc/rsyncd.secrets' + }, }, merge=salt['pillar.get']('rsyncd:lookup')) %} diff --git a/test/pillar/example.sls b/test/pillar/example.sls new file mode 120000 index 0000000..837da91 --- /dev/null +++ b/test/pillar/example.sls @@ -0,0 +1 @@ +../../pillar.example \ No newline at end of file diff --git a/test/pillar/top.sls b/test/pillar/top.sls new file mode 100644 index 0000000..7bd0c36 --- /dev/null +++ b/test/pillar/top.sls @@ -0,0 +1,3 @@ +base: + '*': + - example