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 | |
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')
-rw-r--r-- | manifests/base.pp | 8 | ||||
-rw-r--r-- | manifests/bigcouch/add_node.pp | 7 | ||||
-rw-r--r-- | manifests/bigcouch/document.pp | 9 | ||||
-rw-r--r-- | manifests/bigcouch/query.pp | 10 | ||||
-rw-r--r-- | manifests/create_db.pp | 8 | ||||
-rw-r--r-- | manifests/document.pp | 44 | ||||
-rw-r--r-- | manifests/query.pp | 4 |
7 files changed, 71 insertions, 19 deletions
diff --git a/manifests/base.pp b/manifests/base.pp index fb87ae9..f1e33f1 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -32,6 +32,7 @@ class couchdb::base { } File['/usr/local/bin/couch-doc-update'] -> Couchdb::Update <| |> + File['/usr/local/bin/couch-doc-diff'] -> Couchdb::Update <| |> file { '/usr/local/bin/couch-doc-update': @@ -41,6 +42,13 @@ class couchdb::base { group => 'root', require => Package['couchrest']; + '/usr/local/bin/couch-doc-diff': + source => 'puppet:///modules/couchdb/couch-doc-diff', + mode => '0755', + owner => 'root', + group => 'root', + require => Package['couchrest']; + '/etc/couchdb/local.ini': source => [ "puppet:///modules/site_couchdb/${::fqdn}/local.ini", 'puppet:///modules/site_couchdb/local.ini', diff --git a/manifests/bigcouch/add_node.pp b/manifests/bigcouch/add_node.pp index da10db2..ed9db94 100644 --- a/manifests/bigcouch/add_node.pp +++ b/manifests/bigcouch/add_node.pp @@ -1,7 +1,8 @@ define couchdb::bigcouch::add_node { - couchdb::bigcouch::query { "add_${name}": - cmd => 'PUT', - url => "nodes/bigcouch@${name}" + couchdb::bigcouch::document { "add_${name}": + db => 'nodes', + id => "bigcouch@${name}", + ensure => 'present' } } diff --git a/manifests/bigcouch/document.pp b/manifests/bigcouch/document.pp new file mode 100644 index 0000000..f72f205 --- /dev/null +++ b/manifests/bigcouch/document.pp @@ -0,0 +1,9 @@ +define couchdb::bigcouch::document ( $host='127.0.0.1:5986', $db, $id, $data='{}', $ensure='content') { + couchdb::document { "${name}": + host => $host, + db => $db, + id => $id, + data => $data, + ensure => $ensure + } +} diff --git a/manifests/bigcouch/query.pp b/manifests/bigcouch/query.pp deleted file mode 100644 index cecfe5a..0000000 --- a/manifests/bigcouch/query.pp +++ /dev/null @@ -1,10 +0,0 @@ -define couchdb::bigcouch::query ( - $cmd, $url, $host='127.0.0.1:5986', $data = '{}' ) { - - couchdb::query { "${name}": - cmd => $cmd, - host => $host, - url => $url, - data => $data - } -} diff --git a/manifests/create_db.pp b/manifests/create_db.pp index 22b3236..afab7b5 100644 --- a/manifests/create_db.pp +++ b/manifests/create_db.pp @@ -4,7 +4,7 @@ define couchdb::create_db ( $readers="{\"names\": [], \"roles\": [] }" ) { - Couchdb::Query["create_db_${name}"] -> Couchdb::Query["db_security_${name}"] + Couchdb::Query["create_db_${name}"] -> Couchdb::Document["${name}_security"] couchdb::query { "create_db_${name}": cmd => 'PUT', @@ -13,10 +13,10 @@ define couchdb::create_db ( unless => "/usr/bin/curl -s --netrc-file /etc/couchdb/couchdb.netrc ${host}/${name} | grep -q -v '{\"error\":\"not_found\"'" } - couchdb::query { "db_security_${name}": - cmd => 'PUT', + couchdb::document { "${name}_security": + db => $name, + id => '_security', host => $host, - url => "${name}/_security", data => "{ \"admins\": ${admins}, \"readers\": ${readers} }" } } 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}" + } + } + } +} diff --git a/manifests/query.pp b/manifests/query.pp index 6d13c2b..0549ded 100644 --- a/manifests/query.pp +++ b/manifests/query.pp @@ -1,7 +1,7 @@ define couchdb::query ( - $cmd, $url, $host='127.0.0.1:5984', $data = '{}', $unless = undef) { + $cmd, $path, $host='127.0.0.1:5984', $data = '{}', $unless = undef) { - exec { "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc -X ${cmd} ${host}/${url} --data \'${data}\'": + exec { "/usr/bin/curl --netrc-file /etc/couchdb/couchdb.netrc -X ${cmd} ${host}/${path} --data \'${data}\'": require => [ Package['curl'], Exec['wait_for_couchdb'] ], unless => $unless } |