Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Dockefile and updated partial_search hostname #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ruby:2.2.5

RUN mkdir -p /opt/chef-rundeck; mkdir -p /opt/knife

RUN apt-get install git -y

RUN git clone https:/ehlerst/chef-rundeck.git /opt/chef-rundeck

### Get deps ready
RUN gem install jeweler

RUN cd /opt/chef-rundeck; gem build chef-rundeck.gemspec; gem install chef-rundeck

EXPOSE 9980

CMD ["/usr/local/bundle/bin/chef-rundeck", "-c", "/opt/knife/knife.rb", "-o", "0.0.0.0", "-t", "3600", "--partial-search", "true"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ A simple Sinatra app that presents matching node results of a Chef search format
Install the gem and fire up chef-rundeck. Point it at a Chef client config file (a knife config would be ideal) using
the `-c` flag and provide the URI for your Chef server's web UI.

To use with docker make your config files and mount the volume like this:
`docker run -d -e 'USER=${job.username}' -v ~/.chef/chef-rundeck:/opt/knife -p 9980:9980 ehlers320/chef-rundeck:latest`

## Configuration Notes

chef-rundeck binds to "localhost," which may result in it binding to an IPv6-only address in certain configurations.
Expand Down
7 changes: 4 additions & 3 deletions lib/chef-rundeck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def build_project (project="default", pattern="*:*", username=ChefRundeck.userna
'platform' => [ 'platform'],
'platform_version' => [ 'platform_version' ],
'tags' => [ 'tags' ],
'ipaddress' => [ 'ipaddress' ],
'hostname' => [hostname]
}
if !custom_attributes.nil? then
Expand Down Expand Up @@ -186,7 +187,7 @@ def build_node (node, username, hostname, custom_attributes)
tags="#{xml_escape([ node['roles'], node['recipes'], node['chef_environment'], node['tags']].flatten.join(","))}"
environment="#{xml_escape(node['chef_environment'])}"
username="#{xml_escape(username)}"
hostname="#{xml_escape(node['hostname'])}"
hostname="#{xml_escape(node['ipaddress'])}"
editUrl="#{xml_escape(ChefRundeck.web_ui_url)}/nodes/#{xml_escape(node['name'])}/edit" #{custom_attributes.nil? ? '/': ''}>
EOH
if !custom_attributes.nil? then
Expand Down Expand Up @@ -315,12 +316,12 @@ def partial_search(type, query='*:*', *args, &block)
end
# If you pass a block, or have the start or rows arguments, do raw result parsing
if Kernel.block_given? || args_hash[:start] || args_hash[:rows]
PartialSearch.new.search(type, query, args_hash, &block)
Chef::PartialSearch.new.search(type, query, args_hash, &block)

# Otherwise, do the iteration for the end user
else
results = Array.new
PartialSearch.new.search(type, query, args_hash) do |o|
Chef::PartialSearch.new.search(type, query, args_hash) do |o|
results << o
end
results
Expand Down
88 changes: 45 additions & 43 deletions lib/partial_search.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: John Keiser (<jkeiser@opscode.com>)
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: John Keiser (<jkeiser@chef.io>)
# Copyright:: Copyright (c) 2012 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -27,54 +27,56 @@
require 'chef/data_bag'
require 'chef/data_bag_item'

class PartialSearch
class Chef
class PartialSearch
attr_accessor :rest

attr_accessor :rest

def initialize(url=nil)
@rest = ::Chef::REST.new(url || ::Chef::Config[:chef_server_url])
end
def initialize(url = nil)
@rest = ::Chef::REST.new(url || ::Chef::Config[:chef_server_url])
end

# Search Solr for objects of a given type, for a given query. If you give
# it a block, it will handle the paging for you dynamically.
def search(type, query='*:*', args={}, &block)
raise ArgumentError, "Type must be a string or a symbol!" unless (type.kind_of?(String) || type.kind_of?(Symbol))
# Search Solr for objects of a given type, for a given query. If you give
# it a block, it will handle the paging for you dynamically.
def search(type, query = '*:*', args = {}, &block)
fail ArgumentError, 'Type must be a string or a symbol!' unless type.is_a?(String) || type.is_a?(Symbol)

sort = args.include?(:sort) ? args[:sort] : 'X_CHEF_id_CHEF_X asc'
start = args.include?(:start) ? args[:start] : 0
rows = args.include?(:rows) ? args[:rows] : 1000
query_string = "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}"
if args[:keys]
response = @rest.post_rest(query_string, args[:keys])
response_rows = response['rows'].map { |row| row['data'] }
else
response = @rest.get_rest(query_string)
response_rows = response['rows']
end
if block
response_rows.each { |o| block.call(o) unless o.nil?}
unless (response["start"] + response_rows.length) >= response["total"]
nstart = response["start"] + rows
args_hash = {
:keys => args[:keys],
:sort => sort,
:start => nstart,
:rows => rows
}
search(type, query, args_hash, &block)
sort = args.include?(:sort) ? args[:sort] : 'X_CHEF_id_CHEF_X asc'
start = args.include?(:start) ? args[:start] : 0
rows = args.include?(:rows) ? args[:rows] : 1000
query_string = "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}"
if args[:keys]
response = @rest.post_rest(query_string, args[:keys])
response_rows = response['rows'].map { |row| row['data'] }
else
response = @rest.get_rest(query_string)
response_rows = response['rows']
end
if block
response_rows.each { |o| block.call(o) unless o.nil? }
unless (response['start'] + response_rows.length) >= response['total']
nstart = response['start'] + rows
args_hash = {
keys: args[:keys],
sort: sort,
start: nstart,
rows: rows
}
search(type, query, args_hash, &block)
end
true
else
[response_rows, response['start'], response['total']]
end
true
else
[ response_rows, response["start"], response["total"] ]
end
end

def list_indexes
response = @rest.get_rest("search")
end
def list_indexes
@rest.get_rest('search')
end

private

private
def escape(s)
s && URI.escape(s.to_s)
end
end
end