Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make lsyncd delete-option configurable #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ lsyncd::rsync:
archive: true
```

# Deletions

"[By default](https://axkibe.github.io/lsyncd/manual/config/layer4/#deletions) Lsyncd will delete files on the target that are not present at the source".
If you need to divert from this behaviour, set one of the other possible flags (false|startup|running).

```yaml
source: /tmp/source
target: /tmp/target
delete: false
```

# Alternatives
You might prefer [this lsyncd module](https://github.com/spjmurray/puppet-lsyncd) for Ubuntu, or [this one](https://github.com/thias/puppet-lsyncd) for RHEL.
1 change: 1 addition & 0 deletions manifests/rsync.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$source = undef,
$target = undef,
$ensure = present,
$delete = true,
$options = {},
) {
lsyncd::sync::rsync{$name:
Expand Down
1 change: 1 addition & 0 deletions manifests/sync/rsync.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$source = undef,
$target = undef,
$ensure = present,
$delete = true,
$options = {},
) {
$path = "${lsyncd::config_dir}/sync.d/${name}.conf.lua"
Expand Down
1 change: 1 addition & 0 deletions manifests/sync/rsyncssh.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$targetdir,
$host,
$ensure = present,
$delete = true,
$rsync_options = {},
$ssh_options = {},
) {
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "negz-lsyncd",
"version": "1.2.2",
"version": "1.2.3",
"author": "Nic Cope",
"license": "Apache-2.0",
"summary": "Yet another lsyncd module",
Expand Down
7 changes: 7 additions & 0 deletions templates/rsync.conf.lua.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ sync {
default.rsync,
source = "<%= @source %>",
target = "<%= @target %>",
<%- if @delete != true -%>
<%- if @delete == false -%>
delete = <%= @delete %>,
<%- else -%>
delete = "<%= @delete %>",
<%- end -%>
<%- end -%>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I really appreciate you taking the time.

The only part I can't quite follow is this block (and the similar block in rsyncssh.conf.lua.erb). Is there a reason we can't just add delete = <%= @delete %> to the templates without the surrounding conditionals?

Copy link
Author

@wbob wbob Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Nic - I appreciate your willingness to look into it.

The reason for the first conditional was to cause no change in config files for existing configurations. As true is the default I opted to not print it then.

As for the second conditional, reading the doc it seems to me the first two options are boolean, the former ones string.
I just tested to include the modes running/startup unquoted and they do not follow their advertised behaviour - i.e. startup is not supposed to delete on target during runtime, but will do so if the setting is placed unquoted (as it resolves to bool true?). Same goes for printing true quoted, it will not delete on target. Maybe I should look into lsyncd if they can all be made strings.

If the control structure / indentation looks awkward or introduces confusion and you prefer any other way, please change. To me the distinction boolean/string-option proved to be important and therefore at least one conditional separating the option types is needed.

rsync = {
<% @options.each do |key, val| -%>
<%= key %> = <%= val %>,
Expand Down
7 changes: 7 additions & 0 deletions templates/rsyncssh.conf.lua.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ sync {
default.rsyncssh,
source = "<%= @source %>",
targetdir = "<%= @targetdir %>",
<%- if @delete != true -%>
<%- if @delete == false -%>
delete = <%= @delete %>,
<%- else -%>
delete = "<%= @delete %>",
<%- end -%>
<%- end -%>
host = "<%= @host %>",
rsync = {
<% @rsync_options.each do |key, val| -%>
Expand Down