diff options
author | varac <varacanero@zeromail.org> | 2013-08-29 19:26:36 +0200 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2013-08-29 19:26:36 +0200 |
commit | 32a0f9df6e80c15b3b49b8ad81b9a49ecc6f39dd (patch) | |
tree | 7d180ca7bf135523969956ed468b6224ff44ece8 /manifests/document.pp | |
parent | 61eca267cb52252371a71926a64d7f3b7350489d (diff) | |
parent | 321d463b43dc44a4f313aa6dabef1a8bdce27122 (diff) |
Merge branch 'master' of ssh://code.leap.se/puppet_couchdb
Conflicts:
manifests/create_db.pp
Diffstat (limited to 'manifests/document.pp')
-rw-r--r-- | manifests/document.pp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/manifests/document.pp b/manifests/document.pp new file mode 100644 index 0000000..77296dc --- /dev/null +++ b/manifests/document.pp @@ -0,0 +1,44 @@ +# Usage: +# couchdb::document { id: +# db => "database", +# data => "content", +# ensure => {absent,present,*content*} +# } +# +define couchdb::document( + $db, + $id, + $host = '127.0.0.1:5984', + $data = '{}', + $ensure = 'content') { + + $url = "${host}/${db}/${id}" + + case $ensure { + default: { err ( "unknown ensure value '${ensure}'" ) } + content: { + exec { "couch-doc-update --host ${host} --db ${db} --id ${id} --data \'${data}\'": + require => Exec['wait_for_couchdb'], + unless => "couch-doc-diff $url '$data'" + } + } + + present: { + couchdb::query { "create_${db}_${id}": + cmd => 'PUT', + host => $host, + path => "${db}/${id}", + unless => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${url}" + } + } + + absent: { + couchdb::query { "destroy_${db}_${id}": + cmd => 'DELETE', + host => $host, + path => "${db}/${id}", + onlyif => "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc ${url}" + } + } + } +} |