foreman_host_rundeck 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmMzMTViYjY4ZDUzZjlmMzVjNDUwZWJhMWE1NTI5ZDAyNTVkMWM2Yw==
4
+ ODU3YjRlMmExZTI3MjQ0NWVkY2ViZTRjYzk1ZjM0ZTY0YWRjOThlYQ==
5
5
  data.tar.gz: !binary |-
6
- NGNkNGM0NWNiNmMxNWIxMWVmZTUwNmQzNDQxNTA1NmE3NzY0YWVlNQ==
6
+ ZTNhM2Y3MzQyMjZlNmViODcyYjI3ODQwNjY0MjY2MzY2NDRkODJhYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjJhMWUwNDI4MWY0MGM2OTNjZjc4MTU4OTk4ZTQ2ZDYzZjk0Zjg3YjFjYzZl
10
- YjQwNTJmMTNmYzRiMTcwZTdiMjQwMGY3NDBmMzhjMTdjZTIwMTY5Njc3NGEy
11
- N2E3MWY5MGYyOGQzMTFiMTA0YTFkNjYxNjlmZTc0NmYxMjEwNTY=
9
+ NmZjYjJhYTUyODRlMzIzODc4Nzk5MWJiMDBlOWY4N2Y5YzdkZGQ0Y2JiZjA3
10
+ N2ExODA3NGJiMjQzNTI2MWY3NjY0NWNkMDMzNmUyOTVhZjY3YjRlM2UzNzQw
11
+ NGZlYjEzYmUxNDBiMDRkNDAzMjM2ZjE1NjM2YWY1NjEyOTVlODc=
12
12
  data.tar.gz: !binary |-
13
- YzcwYzBmYmE3NGUwYmM0ZGY2YWM5NWMzZWJhM2M0MWE2N2I5OGEyN2VhODhm
14
- ZDQzNDkwNTFkNGFkN2Y2OWE4Y2JiMjJmOTkzYjVmOTBhMjRmMTJhNWQ5Mjc4
15
- MzQ3NmQ5MDg4MWIzNWU0OGYxZDdkMWM1NjZlYjEwZGUyYzZlYzE=
13
+ N2VhOGNjZGIzOTQyMTUwODhmZDMxZDBlYmY0YTZkZTg1ODM0ZGZhYTFhN2Zi
14
+ YWNmNWQ2ZTZmMDRmNDk2NjBiNWNkMzNiZTA2NGNmNWU5N2Y5OTA3OGM1NDM3
15
+ MTliOWZmNjUyNGRhZTI3MTNiMTYyMmM0ODZkYjg4MmZkZTU2NTA=
data/README.md CHANGED
@@ -1,11 +1,53 @@
1
- # ForemanHostRundeck
1
+ # Foreman Host Rundeck
2
2
 
3
3
  Creates a yaml representation of rundeck on hosts
4
4
 
5
+ * Website: [TheForeman.org](http://theforeman.org)
6
+ * ServerFault tag: [Foreman](http://serverfault.com/questions/tagged/foreman)
7
+ * Issues: [foreman_rundeck Redmine](http://projects.theforeman.org/projects/rundeck/issues)
8
+ * Wiki: [Foreman wiki](http://projects.theforeman.org/projects/foreman/wiki/About)
9
+ * Community and support: #theforeman for general support, #theforeman-dev for development chat in [Freenode](irc.freenode.net)
10
+ * Mailing lists:
11
+ * [foreman-users](https://groups.google.com/forum/?fromgroups#!forum/foreman-users)
12
+ * [foreman-dev](https://groups.google.com/forum/?fromgroups#!forum/foreman-dev)
13
+
5
14
  ## Installation
6
15
 
7
- See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
8
- for how to install Foreman plugins
16
+ Please see the Foreman manual for appropriate instructions:
17
+
18
+ * [Foreman: How to Install a Plugin](http://theforeman.org/plugins/)
19
+
20
+ ### Red Hat, CentOS, Fedora, Scientific Linux (rpm)
21
+
22
+ Set up the repo as explained in the link above, then run (on 1.10+):
23
+
24
+ # yum install tfm-rubygem-foreman_host_rundeck
25
+
26
+ On 1.9:
27
+
28
+ # yum install ruby193-rubygem-foreman_host_rundeck
29
+
30
+ ### Debian, Ubuntu (deb)
31
+
32
+ Set up the repo as explained in the link above, then run:
33
+
34
+ # apt-get install ruby-foreman-host-rundeck
35
+
36
+ ### Bundle (gem)
37
+
38
+ Add the following to bundler.d/Gemfile.local.rb in your Foreman installation directory (/usr/share/foreman by default)
39
+
40
+ $ gem 'foreman_host_rundeck'
41
+
42
+ Then run `bundle install` and `foreman-rake db:migrate` from the same directory
43
+
44
+ --------------
45
+
46
+ To verify that the installation was successful, go to Foreman, top bar **Administer > About** and check 'foreman_host_rundeck' shows up in the **System Status** menu under the Plugins tab.
47
+
48
+ ## Usage
49
+
50
+ [Our wiki covers the basics of Rundeck integration](http://projects.theforeman.org/projects/foreman/wiki/Rundeck_Integration)
9
51
 
10
52
  ## Contributing
11
53
 
@@ -7,20 +7,20 @@ module ForemanHostRundeck
7
7
  alias_method_chain :show, :rundeck
8
8
  end
9
9
 
10
- def index_with_rundeck
10
+ def index_with_rundeck(title = nil)
11
11
  if params[:format] == 'yaml'
12
12
  result = {}
13
13
  hosts = resource_base.search_for(params[:search], :order => params[:order]).includes(included_associations)
14
14
  hosts.each { |h| result.update(RundeckFormatter.new(h).output) }
15
15
  render :text => result.to_yaml
16
16
  else
17
- index_without_rundeck
17
+ index_without_rundeck(title)
18
18
  end
19
19
  end
20
20
 
21
21
  def show_with_rundeck
22
22
  if params[:format] == 'yaml'
23
- render :text => RundeckFormatter.new(@host).output.to_yaml
23
+ render :text => RundeckFormatter.new(@host, params[:add_enc_output]).output.to_yaml
24
24
  else
25
25
  show_without_rundeck
26
26
  end
@@ -1,27 +1,47 @@
1
1
  class RundeckFormatter
2
2
  attr_reader :host
3
3
 
4
- delegate :comment, :name, :arch, :environment, :os, :facts_hash, :puppetclasses_names, :params, :to => :host
4
+ delegate :comment, :name, :arch, :environment, :os, :facts_hash, :puppetclasses_names, :params,
5
+ :hostgroup, :organization, :location, :info, :to => :host
5
6
  delegate :logger, :to => :Rails
6
7
 
7
- def initialize(host)
8
+ def initialize(host, include_enc_output = false)
8
9
  @host = host
10
+ @include_enc_output = include_enc_output
9
11
  end
10
12
 
11
13
  def output
12
14
  rdecktags = puppetclasses_names.map { |k| "class=#{k}" }
13
15
  unless params['rundeckfacts'].empty?
14
- rdecktags += params['rundeckfacts'].gsub(/\s+/, '').split(',').map { |rdf| "#{rdf}=" + (facts_hash[rdf] || 'undefined') }
16
+ rdecktags += format_tags(params,'rundeckfacts', facts_hash)
15
17
  end
16
18
 
17
- {name => {'description' => comment, 'hostname' => name, 'nodename' => name,
18
- 'Environment' => environment.name,
19
- 'osArch' => arch.name, 'osFamily' => os.family, 'osName' => os.name,
20
- 'osVersion' => os.release, 'tags' => rdecktags,
21
- 'username' => params['rundeckuser'] || 'root'}
22
- }
19
+ unless params['rundeckglobalparams'].empty?
20
+ rdecktags += format_tags(params, 'rundeckglobalparams', params)
21
+ end
22
+
23
+ rundeck_hash = { 'description' => comment, 'hostname' => name, 'nodename' => name,
24
+ 'osArch' => arch.name, 'osFamily' => os.family, 'osName' => os.name,
25
+ 'osVersion' => os.release, 'tags' => rdecktags,
26
+ 'username' => params['rundeckuser'] || 'root'}
27
+ rundeck_hash['Hostgroup'] = hostgroup.name unless hostgroup.nil?
28
+ rundeck_hash['Environment'] = environment.name unless environment.nil?
29
+ rundeck_hash['Enc_output'] = info if @include_enc_output
30
+
31
+ if SETTINGS[:locations_enabled]
32
+ rundeck_hash['Location'] = location.name unless location.nil?
33
+ end
34
+ if SETTINGS[:organizations_enabled]
35
+ rundeck_hash['Organization'] = organization.name unless organization.nil?
36
+ end
37
+
38
+ { name => rundeck_hash }
23
39
  rescue => e
24
40
  logger.warn "Failed to fetch rundeck info for #{to_s}: #{e}"
25
41
  {}
42
+ end
43
+
44
+ def format_tags params, tag, tag_location
45
+ params[tag].gsub(/\s+/, '').split(',').map { |rdf| "#{rdf}=" + (tag_location[rdf] || 'undefined') }
26
46
  end
27
- end
47
+ end
@@ -19,8 +19,6 @@ module ForemanHostRundeck
19
19
  config.to_prepare do
20
20
  begin
21
21
  HostsController.send(:include, ForemanHostRundeck::HostsControllerExtensions)
22
- # rescue => e
23
- # puts "ForemanHostRundeck: skipping engine hook (#{e})"
24
22
  end
25
23
  end
26
24
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanHostRundeck
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,15 +3,17 @@ require 'test_plugin_helper'
3
3
  class HostsControllerTest < ActionController::TestCase
4
4
  setup do
5
5
  User.current = User.find_by_login "admin"
6
+ @host = FactoryGirl.create(:host, :operatingsystem => FactoryGirl.create(:operatingsystem),
7
+ :architecture => FactoryGirl.create(:architecture),
8
+ :puppetclasses => [FactoryGirl.create(:puppetclass)])
6
9
  end
7
10
 
8
-
9
11
  test "index returns YAML output for rundeck" do
10
12
  get :index, {:format => 'yaml'}, set_session_user
11
13
  hosts = YAML.load(@response.body)
12
14
  assert_not_empty hosts
13
15
  host = Host.first
14
- unless (host.nil? || host.name.nil? || hosts.nil? || hosts[host.name].nil?)
16
+ unless host.nil? || host.name.nil? || hosts.nil? || hosts[host.name].nil?
15
17
  assert_equal host.os.name, hosts[host.name]["osName"] # rundeck-specific field
16
18
  end
17
19
  end
@@ -20,10 +22,23 @@ class HostsControllerTest < ActionController::TestCase
20
22
  host = Host.first
21
23
  get :show, {:id => host, :format => 'yaml'}, set_session_user
22
24
  yaml = YAML.load(@response.body)
23
- unless (host.nil? || host.name.nil? || host.os.nil? || yaml[host.name].nil?)
25
+ unless host.nil? || host.name.nil? || host.os.nil? || yaml[host.name].nil?
24
26
  assert_kind_of Hash, yaml[host.name]
25
27
  assert_equal host.name, yaml[host.name]["hostname"]
26
28
  assert_equal host.os.name, yaml[host.name]["osName"] # rundeck-specific field
27
29
  end
28
30
  end
31
+
32
+ test "show with add_enc_output shows enc output in YAML" do
33
+ host = Host.first
34
+ get :show, {:id => host, :format => 'yaml', :add_enc_output => true}, set_session_user
35
+ yaml = YAML.load(@response.body)
36
+ unless host.nil? || host.name.nil? || host.os.nil? || yaml[host.name].nil?
37
+ assert_kind_of Hash, yaml[host.name]
38
+ assert_equal host.name, yaml[host.name]["hostname"]
39
+ assert_equal host.os.name, yaml[host.name]["osName"] # rundeck-specific field
40
+ assert_kind_of Hash, yaml[host.name]["Enc_output"]
41
+ assert_present yaml[host.name]["Enc_output"]
42
+ end
43
+ end
29
44
  end
@@ -3,28 +3,55 @@ require 'test_plugin_helper'
3
3
  class ForemanHostRundeckTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  User.current = User.find_by_login "admin"
6
+ @host = FactoryGirl.create(:host, :operatingsystem => FactoryGirl.create(:operatingsystem),
7
+ :architecture => FactoryGirl.create(:architecture))
6
8
  end
7
9
 
8
10
  test "#rundeck returns hash" do
9
- h = hosts(:one)
10
- rundeck = RundeckFormatter.new(h).output
11
+ rundeck = RundeckFormatter.new(@host).output
11
12
  assert_kind_of Hash, rundeck
12
- assert_equal ['my5name.mydomain.net'], rundeck.keys
13
- assert_kind_of Hash, rundeck[h.name]
14
- assert_equal 'my5name.mydomain.net', rundeck[h.name]['hostname']
15
- assert_equal ["class=auth", "class=base", "class=chkmk", "class=nagios", "class=pam"], rundeck[h.name]['tags']
13
+ assert_equal [@host.name], rundeck.keys
14
+ assert_kind_of Hash, rundeck[@host.name]
15
+ assert_equal @host.hostname, rundeck[@host.name]['hostname']
16
+ assert_equal @host.puppetclasses, rundeck[@host.name]['tags']
16
17
  end
17
18
 
18
19
  test "#rundeck returns extra facts as tags" do
19
- host = hosts(:one)
20
- h = FactoryGirl.create(:host, :os => host.os, :arch => host.arch, :puppetclasses => host.puppetclasses, :environment => host.environment)
21
- h.params['rundeckfacts'] = "kernelversion, ipaddress\n"
22
- h.save!
23
- rundeck = RundeckFormatter.new(h).output
20
+ @host.puppetclasses = [FactoryGirl.create(:puppetclass, :environments => [@host.environment])]
21
+ @host.params['rundeckfacts'] = "kernelversion, ipaddress\n"
22
+ @host.save!
23
+ rundeck = RundeckFormatter.new(@host).output
24
+ assert rundeck[@host.name]['tags'].include?("class=#{@host.puppetclasses.first.name}"), 'puppet class missing'
25
+ assert rundeck[@host.name]['tags'].include?('kernelversion=undefined'), 'kernelversion fact missing'
26
+ assert rundeck[@host.name]['tags'].include?('ipaddress=undefined'), 'ipaddress fact missing'
27
+ end
28
+
29
+ test "#rundeck returns global parameters with values as tags" do
30
+ @host.puppetclasses = [FactoryGirl.create(:puppetclass, :environments => [@host.environment])]
31
+ @host.params['rundeckfacts'] = "kernelversion, ipaddress\n"
32
+ @host.params['rundeckglobalparams'] = "stage\n"
33
+ @host.params['stage'] = "prod"
34
+ @host.save!
35
+ rundeck = RundeckFormatter.new(@host).output
36
+ assert rundeck[@host.name]['tags'].include?('stage=prod'), 'stage parameter missing'
37
+ end
24
38
 
25
- assert rundeck[h.name]['tags'].include?('class=base'), 'puppet class missing'
26
- assert rundeck[h.name]['tags'].include?('kernelversion=undefined'), 'kernelversion fact missing'
27
- assert rundeck[h.name]['tags'].include?('ipaddress=undefined'), 'ipaddress fact missing'
39
+ test "#rundeck returns undefined global parameters as tags" do
40
+ @host.puppetclasses = [FactoryGirl.create(:puppetclass, :environments => [@host.environment])]
41
+ @host.params['rundeckfacts'] = "kernelversion, ipaddress\n"
42
+ @host.params['rundeckglobalparams'] = "someparam, stage\n"
43
+ @host.save!
44
+ rundeck = RundeckFormatter.new(@host).output
45
+ assert rundeck[@host.name]['tags'].include?('someparam=undefined'), 'someparam parameter missing'
46
+ assert rundeck[@host.name]['tags'].include?('stage=undefined'), 'stage parameter missing'
28
47
  end
29
48
 
49
+ test "#rundeck does not returns global parameters that are not in params['rundeckglobalparams']" do
50
+ @host.puppetclasses = [FactoryGirl.create(:puppetclass, :environments => [@host.environment])]
51
+ @host.params['rundeckfacts'] = "kernelversion, ipaddress\n"
52
+ @host.params['rundeckglobalparams'] = "someparam\n"
53
+ @host.save!
54
+ rundeck = RundeckFormatter.new(@host).output
55
+ refute rundeck[@host.name]['tags'].include?('stage=undefined')
56
+ end
30
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_host_rundeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ori Rabin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2015-12-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin to create rundeck output for hosts.
14
14
  email:
@@ -49,12 +49,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  requirements: []
51
51
  rubyforge_project:
52
- rubygems_version: 2.4.1
52
+ rubygems_version: 2.2.2
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: Plugin to create rundeck output for hosts.
56
56
  test_files:
57
- - test/unit/foreman_host_rundeck_test.rb
58
- - test/functional/hosts_controller_test.rb
59
57
  - test/test_plugin_helper.rb
58
+ - test/unit/foreman_host_rundeck_test.rb
60
59
  - test/factories/foreman_host_rundeck_factories.rb
60
+ - test/functional/hosts_controller_test.rb