From 26893ef3e4b1895ddb6a15900744b4bbdb5210ba Mon Sep 17 00:00:00 2001 From: Mikhail Konyakhin Date: Tue, 23 Aug 2016 17:08:08 +0300 Subject: [PATCH 1/4] add feature install from package --- .gitignore | 2 ++ manifests/init.pp | 2 ++ manifests/install.pp | 30 ++++++++++++++++++++++-------- manifests/params.pp | 11 ++++++----- manifests/resource.pp | 5 +++++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 4fada6e..174a6fd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ spec/fixtures .ruby-gemset .vagrant Gemfile.lock +.bundle/ +.project diff --git a/manifests/init.pp b/manifests/init.pp index 095ea64..05555d4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,6 +6,7 @@ $version = $confd::params::version, $installdir = $confd::params::installdir, $sitemodule = $confd::params::sitemodule, + $install_type = $confd::params::install_type, $confdir = $confd::params::confdir, $nodes = $confd::params::nodes, @@ -33,6 +34,7 @@ validate_string($sitemodule) validate_absolute_path($confdir) validate_hash($resources) + validate_re($install_type, ['^src$', '^pkg$']) if $backend { validate_re($backend, ['^etcd$', '^consul$', '^zookeeper$', '^dynamodb$', '^redis$', '^env$']) } if $interval { validate_re($interval, '^\d+') } diff --git a/manifests/install.pp b/manifests/install.pp index ef22a68..7240db0 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -3,13 +3,27 @@ class confd::install { include confd - $binary_src = "puppet:///modules/${confd::sitemodule}/confd-${confd::version}" - - file { "${confd::installdir}/confd": - ensure => present, - links => follow, - owner => 'root', - mode => '0750', - source => $binary_src + case $confd::install_type { + 'pkg': { + package { 'confd': + ensure => $confd::version, + } ~> + service { 'confd': + ensure => 'running', + enable => true, + hasstatus => true, + hasrestart => true, + } + } + default: { + $binary_src = "puppet:///modules/${confd::sitemodule}/confd-${confd::version}" + file { "${confd::installdir}/confd": + ensure => present, + links => follow, + owner => 'root', + mode => '0750', + source => $binary_src + } + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 39f47bd..1c80f5b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,11 +4,12 @@ # It sets variables according to platform # class confd::params { - $confdir = '/etc/confd' - $version = 'latest' - $user = 'root' - $sitemodule = 'site_confd' - $nodes = ['127.0.0.1:4001'] + $confdir = '/etc/confd' + $version = 'latest' + $user = 'root' + $sitemodule = 'site_confd' + $nodes = ['127.0.0.1:4001'] + $install_type = 'src' case $::osfamily { 'Debian': { diff --git a/manifests/resource.pp b/manifests/resource.pp index ff1b2fe..92347d1 100644 --- a/manifests/resource.pp +++ b/manifests/resource.pp @@ -31,11 +31,16 @@ if $mode { validate_re($mode, '^\d+')} $resourcefile = "${confd::confdir}/conf.d/${name}.toml" + $notify = $confd::install_type ? { + 'pkg' => Service['confd'], + default => undef, + } file { $resourcefile: ensure => $ensure, owner => 'root', mode => '0640', content => template('confd/resource.toml.erb'), + notify => $notify, } } From c1953ce38c3c481e76fee133261ffb05bfbe0e89 Mon Sep 17 00:00:00 2001 From: Mikhail Konyakhin Date: Tue, 23 Aug 2016 17:21:34 +0300 Subject: [PATCH 2/4] fix travis-ci tests --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 9c075bb..2c1962c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ source 'https://rubygems.org' group :test do - gem 'rake' + gem 'rake', '10.5.0' + gem 'json', '1.8.3' + gem 'json_pure', '1.8.3' gem 'puppet-lint' gem 'puppet-syntax' gem 'puppetlabs_spec_helper', '1.0.1' From c59378331cbfc0d5a6eb0be5b371df28bf8a689b Mon Sep 17 00:00:00 2001 From: Mikhail Konyakhin Date: Tue, 30 Aug 2016 19:44:51 +0300 Subject: [PATCH 3/4] Fix cyclic dependency. --- manifests/init.pp | 3 ++- manifests/install.pp | 7 +------ manifests/resource.pp | 5 ----- manifests/service.pp | 10 ++++++++++ 4 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 manifests/service.pp diff --git a/manifests/init.pp b/manifests/init.pp index 05555d4..e74977b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -78,5 +78,6 @@ class { 'confd::install': } -> class { 'confd::config': } -> - Confd::Resource <||> + Confd::Resource <||> ~> + class { 'confd::service': } } diff --git a/manifests/install.pp b/manifests/install.pp index 7240db0..b54e72f 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -7,12 +7,7 @@ 'pkg': { package { 'confd': ensure => $confd::version, - } ~> - service { 'confd': - ensure => 'running', - enable => true, - hasstatus => true, - hasrestart => true, + notify => Class['confd::service'], } } default: { diff --git a/manifests/resource.pp b/manifests/resource.pp index 92347d1..ff1b2fe 100644 --- a/manifests/resource.pp +++ b/manifests/resource.pp @@ -31,16 +31,11 @@ if $mode { validate_re($mode, '^\d+')} $resourcefile = "${confd::confdir}/conf.d/${name}.toml" - $notify = $confd::install_type ? { - 'pkg' => Service['confd'], - default => undef, - } file { $resourcefile: ensure => $ensure, owner => 'root', mode => '0640', content => template('confd/resource.toml.erb'), - notify => $notify, } } diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..0d34d15 --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,10 @@ +# == Class confd::service +# +class confd::service { + service { 'confd': + ensure => 'running', + enable => true, + hasstatus => true, + hasrestart => true, + } +} From 2870950c1d817f786c79c4f9f6126350be7c74e8 Mon Sep 17 00:00:00 2001 From: Mikhail Konyakhin Date: Tue, 30 Aug 2016 21:33:20 +0300 Subject: [PATCH 4/4] Add notify from config. --- manifests/init.pp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index e74977b..848d51f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -77,7 +77,9 @@ create_resources('confd::resource', $resources) class { 'confd::install': } -> - class { 'confd::config': } -> + class { 'confd::config': + notify => Class['confd::service'], + } -> Confd::Resource <||> ~> class { 'confd::service': } }