Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5ede5b5de6021e976bfd1d730c52f05f to your computer and use it in GitHub Desktop.
Save anonymous/5ede5b5de6021e976bfd1d730c52f05f to your computer and use it in GitHub Desktop.
require 'puppet/provider/elastic5x_online'
Puppet::Type.type(:elastic5x_elasticsearch_online_role).provide(
:online,
:parent => Puppet::Provider::Elastic5xOnline
) do
desc "Fournisseur pour les rôles ElasticSearch stockés dans ElasticSearch."
mk_resource_methods
def self.resources
output = exec_curl('GET', '/_xpack/security/role')
ressources = []
output.each do |rolename, attributes|
if attributes.key?('indices') and !attributes['indices'].empty?
attributes['indices'].each do |indice|
if indice.key?('query')
indice['query'] = JSON.parse(indice['query'])
end
end
end
ressources << {
:name => rolename,
:ensure => :present,
:cluster => attributes['cluster'],
:run_as => attributes['run_as'],
:indices => attributes['indices'],
:provider => :online,
}
end
return ressources
end
def flush
case @property_flush[:ensure] when :absent
self.class.exec_curl('DELETE', "/_xpack/security/role/#{resource[:name]}")
else
self.class.exec_curl('POST', "/_xpack/security/role/#{resource[:name]}", {
:cluster => resource[:cluster],
:run_as => resource[:run_as],
:indices => resource[:indices],
})
end
@property_hash = self.class.resources.detect { |u| u[:name] == resource[:name] }
end
def self.instances
resources.map do |resource|
new resource
end
end
def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
resource.provider = prov
end
end
end
def initialize(value={})
super(value)
@property_flush = {}
end
def create
@property_flush[:ensure] = :present
end
def exists?
@property_hash[:ensure] == :present
end
def destroy
@property_flush[:ensure] = :absent
end
end
require 'puppet/provider'
class Puppet::Provider::Elastic5xOnline < Puppet::Provider
commands :cat => '/bin/cat'
commands :curl => '/usr/bin/curl'
def self.exec_curl(method, uri, data=nil)
base_url = cat('/root/.es_host').strip
user = cat('/root/.es_master').strip
arguments = []
arguments << '--silent'
arguments << "-X#{method}"
arguments << "--user" << user
arguments << "#{base_url}#{uri}"
if data
data_str = JSON.generate(data)
arguments << '-d' << data_str
end
response = curl(arguments)
result = JSON.parse(response)
if result.key?("error")
raise Puppet::ExecutionFailure, result
else
return result
end
end
end
Error: Could not autoload puppet/provider/elastic5x_elasticsearch_online_role/online: undefined method `[]=' for nil:NilClass
/usr/share/ruby/vendor_ruby/puppet/provider.rb:233:in `has_command'
/usr/share/ruby/vendor_ruby/puppet/provider.rb:181:in `block in commands'
/usr/share/ruby/vendor_ruby/puppet/provider.rb:180:in `each'
/usr/share/ruby/vendor_ruby/puppet/provider.rb:180:in `commands'
/var/lib/puppet/lib/puppet/provider/elastic5x_online.rb:4:in `<class:Elastic5xOnline>'
/var/lib/puppet/lib/puppet/provider/elastic5x_online.rb:3:in `<top (required)>'
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
/var/lib/puppet/lib/puppet/provider/elastic5x_elasticsearch_online_role/online.rb:1:in `<top (required)>'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:62:in `load'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:62:in `load_file'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:77:in `block in loadall'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:75:in `each'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:75:in `loadall'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:213:in `loadall'
/usr/share/ruby/vendor_ruby/puppet/metatype/manager.rb:122:in `newtype'
/var/lib/puppet/lib/puppet/type/elastic5x_elasticsearch_online_role.rb:1:in `<top (required)>'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:62:in `load'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:62:in `load_file'
/usr/share/ruby/vendor_ruby/puppet/util/autoload.rb:199:in `load'
/usr/share/ruby/vendor_ruby/puppet/metatype/manager.rb:163:in `type'
/usr/share/ruby/vendor_ruby/puppet/resource.rb:277:in `resource_type'
/usr/share/ruby/vendor_ruby/puppet/resource.rb:243:in `initialize'
/usr/share/ruby/vendor_ruby/puppet/resource.rb:33:in `new'
/usr/share/ruby/vendor_ruby/puppet/resource.rb:33:in `from_data_hash'
/usr/share/ruby/vendor_ruby/puppet/resource/catalog.rb:342:in `block in from_data_hash'
/usr/share/ruby/vendor_ruby/puppet/resource/catalog.rb:341:in `collect'
/usr/share/ruby/vendor_ruby/puppet/resource/catalog.rb:341:in `from_data_hash'
/usr/share/ruby/vendor_ruby/puppet/util/pson.rb:11:in `pson_create'
/usr/share/ruby/vendor_ruby/puppet/external/pson/pure/parser.rb:305:in `parse_object'
/usr/share/ruby/vendor_ruby/puppet/external/pson/pure/parser.rb:98:in `parse'
/usr/share/ruby/vendor_ruby/puppet/external/pson/common.rb:133:in `parse'
/usr/share/ruby/vendor_ruby/puppet/network/formats.rb:143:in `intern'
/usr/share/ruby/vendor_ruby/puppet/network/format_support.rb:12:in `convert_from'
/usr/share/ruby/vendor_ruby/puppet/indirector/rest.rb:245:in `deserialize_find'
/usr/share/ruby/vendor_ruby/puppet/indirector/rest.rb:103:in `find'
/usr/share/ruby/vendor_ruby/puppet/indirector/indirection.rb:201:in `find'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:294:in `block in retrieve_new_catalog'
/usr/share/ruby/vendor_ruby/puppet/util.rb:335:in `block in thinmark'
/usr/share/ruby/benchmark.rb:296:in `realtime'
/usr/share/ruby/vendor_ruby/puppet/util.rb:334:in `thinmark'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:293:in `retrieve_new_catalog'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:61:in `retrieve_catalog'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:106:in `prepare_and_retrieve_catalog'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:202:in `run_internal'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:134:in `block in run'
/usr/share/ruby/vendor_ruby/puppet/context.rb:64:in `override'
/usr/share/ruby/vendor_ruby/puppet.rb:246:in `override'
/usr/share/ruby/vendor_ruby/puppet/configurer.rb:133:in `run'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:47:in `block (4 levels) in run'
/usr/share/ruby/vendor_ruby/puppet/agent/locker.rb:20:in `lock'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:47:in `block (3 levels) in run'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:117:in `with_client'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:44:in `block (2 levels) in run'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:82:in `run_in_fork'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:43:in `block in run'
/usr/share/ruby/vendor_ruby/puppet/application.rb:179:in `call'
/usr/share/ruby/vendor_ruby/puppet/application.rb:179:in `controlled_run'
/usr/share/ruby/vendor_ruby/puppet/agent.rb:41:in `run'
/usr/share/ruby/vendor_ruby/puppet/application/agent.rb:361:in `onetime'
/usr/share/ruby/vendor_ruby/puppet/application/agent.rb:327:in `run_command'
/usr/share/ruby/vendor_ruby/puppet/application.rb:381:in `block (2 levels) in run'
/usr/share/ruby/vendor_ruby/puppet/application.rb:507:in `plugin_hook'
/usr/share/ruby/vendor_ruby/puppet/application.rb:381:in `block in run'
/usr/share/ruby/vendor_ruby/puppet/util.rb:496:in `exit_on_fail'
/usr/share/ruby/vendor_ruby/puppet/application.rb:381:in `run'
/usr/share/ruby/vendor_ruby/puppet/util/command_line.rb:146:in `run'
/usr/share/ruby/vendor_ruby/puppet/util/command_line.rb:92:in `execute'
/usr/bin/puppet:8:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment