From dc367e53b45349ef849247fc93c664c548c90359 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 4 Apr 2013 12:36:24 -0400 Subject: clean-up commit: lint, standardize spacing, properly enclose variables, etc --- manifests/add_user.pp | 6 +++--- manifests/backup.pp | 10 ++++++---- manifests/base.pp | 23 +++++++++++------------ manifests/bigcouch.pp | 2 +- manifests/bigcouch/debian.pp | 2 ++ manifests/bigcouch/package/cloudant.pp | 10 ++++------ manifests/conf.pp | 0 manifests/create_db.pp | 27 +++++++-------------------- manifests/debian.pp | 7 ++++--- manifests/deploy_config.pp | 1 + manifests/init.pp | 11 +++++++---- manifests/params.pp | 18 +++++++++--------- manifests/query.pp | 3 ++- manifests/query/setup.pp | 1 + manifests/ssl/deploy_cert.pp | 14 +++++++------- manifests/ssl/generate_cert.pp | 12 ++++++------ manifests/update.pp | 3 ++- 17 files changed, 73 insertions(+), 77 deletions(-) delete mode 100644 manifests/conf.pp (limited to 'manifests') diff --git a/manifests/add_user.pp b/manifests/add_user.pp index e455124..cd72530 100644 --- a/manifests/add_user.pp +++ b/manifests/add_user.pp @@ -6,10 +6,10 @@ define couchdb::add_user ( $roles, $pw ) { $port = 5984 } - couchdb::update { "update_user_$name": + couchdb::update { "update_user_${name}": port => $port, db => '_users', - id => "org.couchdb.user:$name", - data => "{\"type\": \"user\", \"name\": \"$name\", \"roles\": $roles, \"password\": \"$pw\"}", + id => "org.couchdb.user:${name}", + data => "{\"type\": \"user\", \"name\": \"${name}\", \"roles\": ${roles}, \"password\": \"${pw}\"}", } } diff --git a/manifests/backup.pp b/manifests/backup.pp index 527cf16..6eb48c5 100644 --- a/manifests/backup.pp +++ b/manifests/backup.pp @@ -4,10 +4,10 @@ class couchdb::backup { # used in ERB templates $bind_address = $couchdb::params::bind_address - $port = $couchdb::params::port - $backupdir = $couchdb::params::backupdir + $port = $couchdb::params::port + $backupdir = $couchdb::params::backupdir - file {$couchdb::params::backupdir: + file { $couchdb::params::backupdir: ensure => directory, mode => '0755', require => Package['couchdb'], @@ -29,7 +29,6 @@ class couchdb::backup { require => File['/usr/local/sbin/couchdb-backup.py'], } - case $::operatingsystem { /Debian|Ubunu/: { # note: python-couchdb >= 0.8 required, which is found in debian wheezy. @@ -44,6 +43,9 @@ class couchdb::backup { creates => '/usr/lib/python2.6/site-packages/CouchDB-0.8-py2.6.egg', } } + default: { + err('This module has not been written to support your operating system') + } } } diff --git a/manifests/base.pp b/manifests/base.pp index 7f78995..5b70546 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -7,13 +7,12 @@ class couchdb::base { $couchdb_user = 'couchdb' } - - package {'couchdb': + package { 'couchdb': ensure => present, require => Exec['refresh_apt'] } - service {'couchdb': + service { 'couchdb': ensure => running, hasstatus => true, enable => true, @@ -21,14 +20,12 @@ class couchdb::base { } # todo: make host/port configurable - exec {'wait_for_couchdb': + exec { 'wait_for_couchdb': command => 'wget --retry-connrefused --tries 10 --quiet "http://127.0.0.1:5984" -O /dev/null', require => Service['couchdb'] } # required for couch-doc-update script - - package { 'couchrest': ensure => installed, provider => 'gem' @@ -64,7 +61,7 @@ class couchdb::base { $sha1 = $sha1_and_salt[0] $salt = $sha1_and_salt[1] - file {'/etc/couchdb/local.d/admin.ini': + file { '/etc/couchdb/local.d/admin.ini': content => "[admins] admin = -hashed-${sha1},${salt} ", @@ -75,14 +72,16 @@ admin = -hashed-${sha1},${salt} require => File ['/etc/couchdb/local.d']; } + case $::couchdb::bigcouch { + true: { $restart_command = '/etc/init.d/bigcouch restart; sleep 6' } + default: { $restart_command = '/etc/init.d/couchdb restart; sleep 6' } + } + exec { 'couchdb_restart': - command => $::couchdb::bigcouch ? { - true => '/etc/init.d/bigcouch restart; sleep 6', - default => '/etc/init.d/couchdb restart; sleep 6', - }, + command => $restart_command, path => ['/bin', '/usr/bin',], subscribe => File['/etc/couchdb/local.d/admin.ini', - '/etc/couchdb/local.ini'], + '/etc/couchdb/local.ini'], refreshonly => true } diff --git a/manifests/bigcouch.pp b/manifests/bigcouch.pp index 4f22f8a..9beea75 100644 --- a/manifests/bigcouch.pp +++ b/manifests/bigcouch.pp @@ -1,6 +1,6 @@ class couchdb::bigcouch inherits couchdb::base { - file {'/etc/couchdb': + file { '/etc/couchdb': ensure => link, target => '/opt/bigcouch/etc', require => Package['couchdb'] diff --git a/manifests/bigcouch/debian.pp b/manifests/bigcouch/debian.pp index 54ca882..8af3993 100644 --- a/manifests/bigcouch/debian.pp +++ b/manifests/bigcouch/debian.pp @@ -1,7 +1,9 @@ class couchdb::bigcouch::debian inherits couchdb::debian { + File ['/etc/init.d/couchdb'] { ensure => absent } + file {'/etc/init.d/bigcouch': ensure => link, target => '/usr/bin/sv' diff --git a/manifests/bigcouch/package/cloudant.pp b/manifests/bigcouch/package/cloudant.pp index 4c44e74..88ee8da 100644 --- a/manifests/bigcouch/package/cloudant.pp +++ b/manifests/bigcouch/package/cloudant.pp @@ -1,19 +1,17 @@ class couchdb::bigcouch::package::cloudant { - - # cloudants signing key can be fetched from + # cloudant's signing key can be fetched from # http://packages.cloudant.com/KEYS, please use the apt module to - # distribute it on your servers - # It's verified fingerprint is: - # BAF9 B315 D438 5FB9 B5DE 334B 59E0 1FBD 15BE 8E26 + # distribute it on your servers after verifying its fingerprint apt::sources_list {'bigcouch-cloudant.list': content => 'deb http://packages.cloudant.com/debian squeeze main' } # right now, cloudant only provides authenticated ibigcouch 0.4.2 packages - # for squeeze, therefore we need to include squeeze repo for depending + # for squeeze, therefore we need to include squeeze repo for depending # packages + if $::lsbdistcodename == 'wheezy' { apt::sources_list {'squeeze.list': content => 'deb http://http.debian.net/debian squeeze main diff --git a/manifests/conf.pp b/manifests/conf.pp deleted file mode 100644 index e69de29..0000000 diff --git a/manifests/create_db.pp b/manifests/create_db.pp index b81dbed..b080b06 100644 --- a/manifests/create_db.pp +++ b/manifests/create_db.pp @@ -1,10 +1,11 @@ define couchdb::create_db ( $host='127.0.0.1:5984', - $admins="{\"names\": [], \"roles\": [] }", - $readers="{\"names\": [], \"roles\": [] }") { + $admins='{\"names\": [], \"roles\": [] }', + $readers='{\"names\": [], \"roles\": [] }' ) +{ - Couchdb::Query["create_db_$name"] -> Couchdb::Query["db_security_${name}"] + Couchdb::Query["create_db_${name}"] -> Couchdb::Query["db_security_${name}"] - couchdb::query { "create_db_$name": + couchdb::query { "create_db_${name}": cmd => 'PUT', host => $host, url => $name, @@ -13,21 +14,7 @@ define couchdb::create_db ( $host='127.0.0.1:5984', couchdb::query { "db_security_${name}": cmd => 'PUT', host => $host, - url => "$name/_security", - data => "{ \"admins\": $admins, \"readers\": $readers }" + url => "${name}/_security", + data => "{ \"admins\": ${admins}, \"readers\": ${readers} }" } - - #couchdb::update { "create_db_$name": - # db => $name, - # id => '', - # data => '' - #} - - #couchdb::update { "db_security_$name": - # db => $name, - # id => '_security', - # data => "{ \"admins\": $admins, \"readers\": $readers }" - #} - - } diff --git a/manifests/debian.pp b/manifests/debian.pp index 2a7417e..e55ad48 100644 --- a/manifests/debian.pp +++ b/manifests/debian.pp @@ -1,11 +1,12 @@ class couchdb::debian inherits couchdb::base { - package {'libjs-jquery': + package { 'libjs-jquery': ensure => present, } - file {'/etc/init.d/couchdb': + + file { '/etc/init.d/couchdb': source => [ 'puppet:///modules/site_couchdb/Debian/couchdb', - 'puppet:///modules/couchdb/Debian/couchdb' ], + 'puppet:///modules/couchdb/Debian/couchdb' ], mode => '0755', owner => 'root', group => 'root', diff --git a/manifests/deploy_config.pp b/manifests/deploy_config.pp index 4070221..2ce1fd2 100644 --- a/manifests/deploy_config.pp +++ b/manifests/deploy_config.pp @@ -1,4 +1,5 @@ class couchdb::deploy_config { + file { '/etc/couchdb/local.ini': source => [ "puppet:///modules/site_couchdb/${::fqdn}/local.ini", 'puppet:///modules/site_couchdb/local.ini', diff --git a/manifests/init.pp b/manifests/init.pp index d62bb9e..070baae 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,7 +1,10 @@ -class couchdb ( - $admin_pw, - $bigcouch = false, - $bigcouch_cookie = '' ) { +class couchdb ( $admin_pw = '', $bigcouch = false, $bigcouch_cookie = '' ) +{ + + if $admin_pw = '' { + err('Must set admin password by passing a value to the $admin_pw parameter') + } + case $::operatingsystem { Debian: { case $::lsbdistcodename { diff --git a/manifests/params.pp b/manifests/params.pp index 8993282..02d5f02 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,23 +1,23 @@ class couchdb::params { - $bind_address = $couchdb_bind_address ? { + $bind_address = $::couchdb_bind_address ? { '' => '127.0.0.1', - default => $couchdb_bind_address, + default => $::couchdb_bind_address, } - $port = $couchdb_port ? { + $port = $::couchdb_port ? { '' => '5984', - default => $couchdb_port, + default => $::couchdb_port, } - $backupdir = $couchdb_backupdir ? { + $backupdir = $::couchdb_backupdir ? { '' => '/var/backups/couchdb', - default => $couchdb_backupdir, + default => $::couchdb_backupdir, } - $cert_path = $couchdb_cert_path ? { - "" => "/etc/couchdb", - default => $couchdb_cert_path, + $cert_path = $::couchdb_cert_path ? { + "" => '/etc/couchdb', + default => $::couchdb_cert_path, } } diff --git a/manifests/query.pp b/manifests/query.pp index d912278..20e331d 100644 --- a/manifests/query.pp +++ b/manifests/query.pp @@ -1,5 +1,6 @@ define couchdb::query ( $cmd, $url, $host='127.0.0.1:5984', $data = '' ) { - 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}/${url} --data \'${data}\'": require => [ Package['curl'], Exec['wait_for_couchdb'] ] } } diff --git a/manifests/query/setup.pp b/manifests/query/setup.pp index a36cade..b68e54f 100644 --- a/manifests/query/setup.pp +++ b/manifests/query/setup.pp @@ -1,4 +1,5 @@ define couchdb::query::setup ($user, $pw, $host='127.0.0.1') { + file { '/etc/couchdb/couchdb.netrc': content => "machine ${host} login ${user} password ${pw}", mode => '0600', diff --git a/manifests/ssl/deploy_cert.pp b/manifests/ssl/deploy_cert.pp index 4e9c158..d3e743f 100644 --- a/manifests/ssl/deploy_cert.pp +++ b/manifests/ssl/deploy_cert.pp @@ -1,15 +1,17 @@ define couchdb::ssl::deploy_cert ($cert, $key) { -include couchdb::params + + include couchdb::params + file { 'couchdb_cert_directory': - path => "$couchdb::params::cert_path", ensure => 'directory', + path => $couchdb::params::cert_path, mode => '0600', owner => 'couchdb', group => 'couchdb'; } - file { 'couchdb_cert"': - path => "$couchdb::params::cert_path/server_cert.pem", + file { 'couchdb_cert': + path => "${couchdb::params::cert_path}/server_cert.pem", mode => '0644', owner => 'couchdb', group => 'couchdb', @@ -17,12 +19,10 @@ include couchdb::params } file { 'couchdb_key': - path => "$couchdb::params::cert_path/server_key.pem", + path => "${couchdb::params::cert_path}/server_key.pem", mode => '0600', owner => 'couchdb', group => 'couchdb', content => $key } - - } diff --git a/manifests/ssl/generate_cert.pp b/manifests/ssl/generate_cert.pp index dae091c..3d500ac 100644 --- a/manifests/ssl/generate_cert.pp +++ b/manifests/ssl/generate_cert.pp @@ -6,21 +6,21 @@ class couchdb::ssl::generate_cert { file { $couchdb::cert_path: ensure => 'directory', - mode => '0600', - owner => 'couchdb', - group => 'couchdb'; + mode => '0600', + owner => 'couchdb', + group => 'couchdb'; } - + exec { 'generate-certs': command => "/usr/bin/openssl req -new -inform PEM -x509 -nodes -days 150 -subj \ '/C=ZZ/ST=AutoSign/O=AutoSign/localityName=AutoSign/commonName=${::hostname}/organizationalUnitName=AutoSign/emailAddress=AutoSign/' \ -newkey rsa:2048 -out ${couchdb::cert_path}/couchdb_cert.pem -keyout ${couchdb::cert_path}/couchdb_key.pem", - unless => "/usr/bin/test -f ${couchdb::cert_path}/couchdb_cert.pem && + unless => "/usr/bin/test -f ${couchdb::cert_path}/couchdb_cert.pem && /usr/bin/test -f ${couchdb::params::cert_path}/couchdb_key.pem", require => [ File[$couchdb::params::cert_path], Exec['make-install'] ], - notify => Service['couchdb'], + notify => Service['couchdb'], } } diff --git a/manifests/update.pp b/manifests/update.pp index 7e7be66..b7e6fc1 100644 --- a/manifests/update.pp +++ b/manifests/update.pp @@ -1,5 +1,6 @@ define couchdb::update ($db, $id, $data, $port='5984') { - exec { "couch-doc-update --port $port --db $db --id $id --data \'$data\'": + + exec { "couch-doc-update --port ${port} --db ${db} --id ${id} --data \'${data}\'": require => Exec['wait_for_couchdb'] } } -- cgit v1.2.3