Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request voxpupuli#36 from brucem/hotfix/allow_multiple_tem…
Browse files Browse the repository at this point in the history
…plates

Allow multiple templates
  • Loading branch information
electrical committed Jun 21, 2013
2 parents a5ccf96 + e893328 commit 4f5c0cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 6 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@
notify => $notify_elasticsearch,
}

exec { 'mkdir_templates':
command => "mkdir -p ${elasticsearch::confdir}/templates_import",
cwd => '/',
creates => "${elasticsearch::confdir}/templates_import",
}

}
14 changes: 4 additions & 10 deletions manifests/template.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@
}
}

exec { 'mkdir_templates':
command => "mkdir -p ${elasticsearch::confdir}/templates_import",
cwd => '/',
creates => "${elasticsearch::confdir}/templates_import",
}

$file_ensure = $delete ? {
true => 'absent',
false => 'present'
}

$file_notify = $delete ? {
true => undef,
false => Exec[ 'insert_template' ]
false => Exec[ "insert_template ${name}" ]
}

# place the template file
Expand All @@ -95,13 +89,13 @@

# Only notify the insert_template call when we do a replace.
$exec_notify = $replace ? {
true => Exec[ 'insert_template' ],
true => Exec[ "insert_template ${name}" ],
false => undef
}

# Delete the existing template
# First check if it exists of course
exec { 'delete_template':
exec { "delete_template ${name}":
command => "curl -s -XDELETE ${es_url}",
onlyif => "test $(curl -s '${es_url}?pretty=true' | wc -l) -gt 1",
notify => $exec_notify
Expand All @@ -112,7 +106,7 @@
# Insert the template if we don't delete an existing one
# Before inserting we check if a template exists with that same name
if $delete == false {
exec { 'insert_template':
exec { "insert_template ${name}":
command => "curl -s -XPUT ${es_url} -d @${elasticsearch::confdir}/templates_import/elasticsearch-template-${name}.json",
unless => "test $(curl -s '${es_url}?pretty=true' | wc -l) -gt 1",
refreshonly => true,
Expand Down
12 changes: 6 additions & 6 deletions spec/defines/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
} end

it { should contain_file('/etc/elasticsearch/templates_import/elasticsearch-template-foo.json').with(:source => 'puppet:///path/to/foo.json') }
it { should contain_exec('insert_template').with(:command => 'curl -s -XPUT http://localhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
it { should contain_exec('insert_template foo').with(:command => 'curl -s -XPUT http://localhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
end

context "Delete a template" do
Expand All @@ -23,8 +23,8 @@
} end

it { should_not contain_file('/etc/elasticsearch/templates_import/elasticsearch-template-foo.json').with(:source => 'puppet:///path/to/foo.json') }
it { should_not contain_exec('insert_template') }
it { should contain_exec('delete_template').with(:command => 'curl -s -XDELETE http://localhost:9200/_template/foo', :notify => nil, :onlyif => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1' ) }
it { should_not contain_exec('insert_template foo') }
it { should contain_exec('delete_template foo').with(:command => 'curl -s -XDELETE http://localhost:9200/_template/foo', :notify => nil, :onlyif => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1' ) }
end

context "Replace a template" do
Expand All @@ -35,8 +35,8 @@
} end

it { should contain_file('/etc/elasticsearch/templates_import/elasticsearch-template-foo.json').with(:source => 'puppet:///path/to/foo.json') }
it { should contain_exec('insert_template').with(:command => 'curl -s -XPUT http://localhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
it { should contain_exec('delete_template').with(:command => 'curl -s -XDELETE http://localhost:9200/_template/foo', :notify => 'Exec[insert_template]', :onlyif => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1' ) }
it { should contain_exec('insert_template foo').with(:command => 'curl -s -XPUT http://localhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
it { should contain_exec('delete_template foo').with(:command => 'curl -s -XDELETE http://localhost:9200/_template/foo', :notify => 'Exec[insert_template foo]', :onlyif => 'test $(curl -s \'http://localhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1' ) }

end

Expand All @@ -60,7 +60,7 @@
} end

it { should contain_file('/etc/elasticsearch/templates_import/elasticsearch-template-foo.json').with(:source => 'puppet:///path/to/foo.json') }
it { should contain_exec('insert_template').with(:command => 'curl -s -XPUT http://otherhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://otherhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
it { should contain_exec('insert_template foo').with(:command => 'curl -s -XPUT http://otherhost:9200/_template/foo -d @/etc/elasticsearch/templates_import/elasticsearch-template-foo.json', :unless => 'test $(curl -s \'http://otherhost:9200/_template/foo?pretty=true\' | wc -l) -gt 1') }
end

end

0 comments on commit 4f5c0cf

Please sign in to comment.