From 22d7164e3e50a5e81fe7e04ca45118024c12c8db Mon Sep 17 00:00:00 2001 From: Tim Ski Date: Wed, 16 Apr 2014 18:07:41 -0400 Subject: [PATCH 1/5] Added owner, group, mode to init.pp --- manifests/init.pp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index ad3ad2f..9f94e60 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,6 +19,9 @@ # } # define s3file ( + $owner, + $group, + $mode, $source, $ensure = 'latest', $s3_domain = 's3.amazonaws.com', @@ -30,11 +33,17 @@ if $ensure == 'absent' { # We use a puppet resource here to force the file to absent state file { $name: - ensure => absent + ensure => absent, } } else { $real_source = "https://${s3_domain}/${source}" + file { $name: + owner => $owner, + group => $group, + mode => $mode, + } + if $ensure == 'latest' { $unless = "[ -e ${name} ] && curl -I ${real_source} | grep ETag | grep `md5sum ${name} | cut -c1-32`" } else { From 1ce2eadfeceee44199f7d32c397568d8a4032d1e Mon Sep 17 00:00:00 2001 From: Tim Ski Date: Wed, 16 Apr 2014 18:24:00 -0400 Subject: [PATCH 2/5] Added file before if statements --- manifests/init.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9f94e60..9d04e9a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -30,6 +30,12 @@ $valid_ensures = [ 'absent', 'present', 'latest' ] validate_re($ensure, $valid_ensures) + file { $name: + owner => $owner, + group => $group, + mode => $mode, + } + if $ensure == 'absent' { # We use a puppet resource here to force the file to absent state file { $name: @@ -38,12 +44,6 @@ } else { $real_source = "https://${s3_domain}/${source}" - file { $name: - owner => $owner, - group => $group, - mode => $mode, - } - if $ensure == 'latest' { $unless = "[ -e ${name} ] && curl -I ${real_source} | grep ETag | grep `md5sum ${name} | cut -c1-32`" } else { From c8001b14baff8a9ec2952a4087ed1e8e4b4b6624 Mon Sep 17 00:00:00 2001 From: Mike Lehner Date: Mon, 12 Jan 2015 11:03:25 -0800 Subject: [PATCH 3/5] Adding relationship metaparameter to exec resource Puppet ordering is not deterministic thus requiring us to explicitly set the relationship between resources. In this case, we need the curl command to "require" the file already be created before downloading contents into it. It will still work without this because it frankly doesn't matter if the file resource is called before or after the curl command is run. --- manifests/init.pp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9d04e9a..ece1cdf 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -53,7 +53,8 @@ exec { "fetch ${name}": path => ['/bin', '/usr/bin', 'sbin', '/usr/sbin'], command => "curl -L -o ${name} ${real_source}", - unless => $unless + require => $name, + unless => $unless, } } } From 1e5a5cff5a5b54cc64ee58051062dbe3b1a32e63 Mon Sep 17 00:00:00 2001 From: Mike Lehner Date: Mon, 12 Jan 2015 11:16:08 -0800 Subject: [PATCH 4/5] Adding missing File resource reference --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index ece1cdf..062e4c4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -53,7 +53,7 @@ exec { "fetch ${name}": path => ['/bin', '/usr/bin', 'sbin', '/usr/sbin'], command => "curl -L -o ${name} ${real_source}", - require => $name, + require => File[$name], unless => $unless, } } From a446b515713bec024940c372608b7452baf1e7bc Mon Sep 17 00:00:00 2001 From: Mike Lehner Date: Mon, 12 Jan 2015 13:48:52 -0800 Subject: [PATCH 5/5] Moving file resource inside the else Moving file resource inside the else to remove the duplicate declaration when ```ensure => absent``` is used --- manifests/init.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 062e4c4..708d2a8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -30,18 +30,18 @@ $valid_ensures = [ 'absent', 'present', 'latest' ] validate_re($ensure, $valid_ensures) - file { $name: - owner => $owner, - group => $group, - mode => $mode, - } - if $ensure == 'absent' { # We use a puppet resource here to force the file to absent state file { $name: ensure => absent, } } else { + file { $name: + owner => $owner, + group => $group, + mode => $mode, + } + $real_source = "https://${s3_domain}/${source}" if $ensure == 'latest' {