foreman_ansible 0.3 → 1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_ansible might be problematic. Click here for more details.

Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -37
  3. data/app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb +37 -0
  4. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +9 -0
  5. data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +28 -0
  6. data/app/jobs/foreman_ansible/run_playbook_job.rb +28 -0
  7. data/app/models/ansible_role.rb +6 -0
  8. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +14 -0
  9. data/app/models/host_ansible_role.rb +11 -0
  10. data/app/overrides/ansible_roles_tab.rb +14 -0
  11. data/app/services/foreman_ansible/inventory_creator.rb +18 -0
  12. data/app/services/foreman_ansible/playbook_creator.rb +23 -0
  13. data/app/services/foreman_ansible/role_player.rb +26 -0
  14. data/app/services/foreman_ansible/roles_importer.rb +24 -0
  15. data/app/views/foreman_ansible/hosts/_tab_content.html.erb +4 -0
  16. data/app/views/foreman_ansible/hosts/_tab_title.html.erb +1 -0
  17. data/config/routes.rb +14 -0
  18. data/db/migrate/20160705082036_create_ansible_role.rb +7 -0
  19. data/db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb +8 -0
  20. data/db/migrate/20160707195442_create_host_ansible_roles.rb +6 -0
  21. data/db/seeds.d/62-ansible_proxy_feature.rb +4 -0
  22. data/lib/foreman_ansible/engine.rb +14 -1
  23. data/lib/foreman_ansible/version.rb +1 -1
  24. data/lib/tasks/foreman_ansible_tasks.rake +2 -1
  25. data/test/factories/ansible_roles.rb +5 -0
  26. data/test/functional/hosts_controller_test.rb +36 -0
  27. data/test/test_plugin_helper.rb +4 -0
  28. data/test/unit/ansible_role_test.rb +8 -0
  29. data/test/unit/host_ansible_role_test.rb +7 -0
  30. metadata +29 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f98cfedfee37e7a9829abe818b80cfc7d553b001
4
- data.tar.gz: 008f22e68ec44bf9aa46e75d9006608df8c2821a
3
+ metadata.gz: fc4ac60019a9a765f9d6952ef2353dd4c67ddac3
4
+ data.tar.gz: 1cdc990b070ea857835c74822b021340640bac56
5
5
  SHA512:
6
- metadata.gz: 1b1a8c519e2f29aaf1cfdb5b8c604e06db5d8dcbf3a7646a25b1e9a2a935e9dab4b0977ae21d56e4623fd022fd6b68db4358efddcb9f1a32ab83755f4b2921cf
7
- data.tar.gz: 54eace7707e28bcb0870cb8e24a270fb473c208c4845bb85c3fbdcf925a1690f0c31577072a5a076502564dde7a1b4ec9c2202336c21bf4b4bc4ea828ffbd2fb
6
+ metadata.gz: 6658351477f153ae2b6b42356ba9cb75515fbfeae8a8a40040e2c80d458b127adb2a2a37171b42dc54ca73b135cfd207aa804d190ad6a63df5b8ae8f211805b7
7
+ data.tar.gz: 20f1305a896c46529bc488044f3a3284feb09290845ecbdd333be2ad616473051aa2160cacca849656164bd8c91b654e063a35b4ad9a9edeaa2e257db37cee4c
data/README.md CHANGED
@@ -1,35 +1,29 @@
1
+ [![Code Climate](https://codeclimate.com/github/theforeman/foreman_ansible/badges/gpa.svg)](https://codeclimate.com/github/theforeman/foreman_ansible)
2
+ [![Gem Version](https://badge.fury.io/rb/foreman_ansible.svg)](https://badge.fury.io/rb/foreman_ansible)
3
+ [![GPL License](https://img.shields.io/github/license/theforeman/foreman_ansible.svg)](https://github.com/theforeman/foreman_ansible/blob/master/LICENSE)
4
+
1
5
  # Foreman Ansible :arrow_forward:
2
6
 
7
+ Reporting and facts import from Ansible to Foreman.
8
+
9
+ * Main website: [theforeman.org](http://theforeman.org)
10
+ * Plugin manual: [foreman_ansible manual](http://theforeman.org/plugins/foreman_ansible/1.x/index.html)
11
+ * ServerFault tag: [Foreman](http://serverfault.com/questions/tagged/foreman)
12
+ * Issues: [foreman ansible on Redmine](http://projects.theforeman.org/projects/ansible/issues)
13
+ * Community and support: [#theforeman](https://kiwiirc.com/client/irc.freenode.net/?#theforeman) for general support, [#theforeman-dev](https://kiwiirc.com/client/irc.freenode.net/?#theforeman-dev) for development chat in [Freenode](irc.freenode.net)
14
+ * Mailing lists:
15
+ * [foreman-users](https://groups.google.com/forum/?fromgroups#!forum/foreman-users)
16
+ * [foreman-dev](https://groups.google.com/forum/?fromgroups#!forum/foreman-dev)
17
+
3
18
  ## Features
4
19
  * Import facts
5
- * Monitor playbook and ansible runs runtime
20
+ * Monitor playbook and Ansible runs runtime
6
21
  * Sends Ansible reports to Foreman that contain what changed on your system after an ansible run.
22
+ * Stores a list of roles applicable to your hosts and 'plays' them
23
+ * Looking for an Ansible dynamic inventory for Foreman? Use [foreman_ansible_inventory](https://github.com/theforeman/foreman_ansible_inventory/)
7
24
 
8
- ## Basic usage
9
-
10
- Install `foreman_ansible` on your Foreman host. See the [Foreman manual: installing plugin from gems](http://www.theforeman.org/plugins/#2.3AdvancedInstallationfromGems)
11
-
12
- Deploy `extras/foreman_callback.py` as a callback on your Ansible installation. For instance, put in your `ansible.cfg`:
13
-
14
- ```
15
- callback_plugins = ~/.ansible/plugins/callback_plugins/
16
- bin_ansible_callbacks = True
17
- ```
18
- And copy `extras/foreman_callback.py` from this repo to `~/.ansible/plugins/callback_plugins/`.
19
-
20
- You can configure it via the following environment variables:
21
-
22
- * FOREMAN_URL: the URL of your Foreman installation (default "http://localhost:3000")
23
- * FOREMAN_SSL_CERT: The public key when using SSL client certificates (default "/etc/foreman/client_cert.pem")
24
- * FOREMAN_SSL_KEY: The private key when using SSL client certificates (default "/etc/foreman/client_key.pem")
25
- * FOREMAN_SSL_VERIFY: wether to verify SSL certificates. Use *False*
26
- to disable certificate checks. You can also set it to CA bundle (default is "True").
27
-
28
- See the [python-requests documentation](http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification) on the details of certificate setup.
29
-
30
- That's it!
31
-
32
- Now, every time you run a playbook or `ansible -m setup $HOSTNAME`, Ansible will automatically submit facts and a small report for $HOSTNAME to Foreman. See 'Extra information' below if you find any error.
25
+ ## Documentation (installation and configuration)
26
+ Check out the official manual at [theforeman.org](http://theforeman.org/plugins/foreman_ansible/1.x/index.html)
33
27
 
34
28
  ##### Registering a new host in Foreman
35
29
  ![sign up gif](http://i.imgur.com/mlnVFJj.gif)
@@ -37,13 +31,18 @@ Now, every time you run a playbook or `ansible -m setup $HOSTNAME`, Ansible wil
37
31
  ##### Host with failed and successful reports
38
32
  ![reports](http://i.imgur.com/1ySO4sh.png)
39
33
 
40
- ### Extra information
34
+ ##### Assigning roles to a host and 'playing' them
35
+ ![role list](http://i.imgur.com/UyeZIq8.png)
36
+ ![role play](http://i.imgur.com/eU4RENK.png)
37
+ ![multiple role play](http://i.imgur.com/uoIiKJ5.png)
41
38
 
42
- In Foreman, you should add whatever Ansible hosts you want to submit facts from to the setting `trusted_puppetmaster_hosts`. Change it at Administer > Settings, Puppet tab.
43
39
 
44
- If the Foreman setting 'create_new_host_when_facts_are_uploaded' is true, and $HOSTNAME doesn't exist in Foreman, it will autocreate that host in Foreman. If it already exists, it will update the facts.
40
+ ## Compatibility
45
41
 
46
- Similarly, the Foreman setting 'ignore_puppet_facts_for_provisioning' is set to false, facts related to interfaces will update the interfaces of $HOSTNAME in Foreman.
42
+ | Foreman | Plugin |
43
+ | ---------------:| --------------:|
44
+ | >= 1.9 | 0 - 0.3 |
45
+ | >= 1.12 | 1.0 - TBD |
47
46
 
48
47
  ### Devs
49
48
 
@@ -53,10 +52,6 @@ Facts must contain the output of `ansible -m setup $HOSTNAME`, plus a '_type' an
53
52
 
54
53
  After that request, you should have a host registered in Foreman with the Ansible facts. It takes into account some facter and ohai facts if these are available on the system as well.
55
54
 
56
- ## Contributing
57
-
58
- Fork and send a Pull Request. Thanks!
59
-
60
55
  ## Copyright
61
56
 
62
57
  Copyright (c) Daniel Lobato Garcia
@@ -73,6 +68,3 @@ GNU General Public License for more details.
73
68
 
74
69
  You should have received a copy of the GNU General Public License
75
70
  along with this program. If not, see <http://www.gnu.org/licenses/>.
76
-
77
-
78
-
@@ -0,0 +1,37 @@
1
+ module ForemanAnsible
2
+ module Concerns
3
+ # Extra methods to enforce Ansible roles on a host or multiple hosts
4
+ module HostsControllerExtensions
5
+ extend ActiveSupport::Concern
6
+
7
+ def play_roles
8
+ find_resource
9
+ RolePlayer.new(@host).play
10
+ notice(_('Ansible roles running on background: ') +
11
+ @host.ansible_roles.map(&:name).join(', '))
12
+ redirect_to :back
13
+ end
14
+
15
+ def multiple_play_roles
16
+ find_multiple
17
+ @hosts.each do |host|
18
+ RolePlayer.new(host).play
19
+ end
20
+ notice(_('Ansible roles running on background for hosts: ') +
21
+ @hosts.map(&:name).join(', '))
22
+ redirect_to :hosts
23
+ end
24
+
25
+ private
26
+
27
+ def action_permission
28
+ case params[:action]
29
+ when 'multiple_play_roles', 'play_roles'
30
+ :view
31
+ else
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module ForemanAnsible
2
+ # Small convenience to list all roles in the UI
3
+ module AnsibleRolesHelper
4
+ def ansible_roles
5
+ ForemanAnsible::RolesImporter.import!
6
+ AnsibleRole.all
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module ForemanAnsible
2
+ # Chained methods to extend the hosts menu with Ansible actions
3
+ module HostsHelperExtensions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ alias_method_chain(:host_title_actions, :run_ansible_roles)
8
+ alias_method_chain(:multiple_actions, :run_ansible_roles)
9
+ end
10
+
11
+ def host_title_actions_with_run_ansible_roles(*args)
12
+ button = link_to(
13
+ icon_text('play', ' ' + _('Ansible roles'), :kind => 'fa'),
14
+ play_roles_ansible_host_path(:id => args.first.id),
15
+ :id => :ansible_roles_button,
16
+ :class => 'btn btn-default')
17
+ title_actions(button_group(button)) if args.first.ansible_roles.present?
18
+ host_title_actions_without_run_ansible_roles(*args)
19
+ end
20
+
21
+ def multiple_actions_with_run_ansible_roles
22
+ multiple_actions_without_run_ansible_roles +
23
+ [[_('Play Ansible roles'),
24
+ multiple_play_roles_ansible_hosts_path,
25
+ false]]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module ForemanAnsible
2
+ # Run the ansible-playbook binary, depends on a valid playbook and inventory
3
+ class RunPlaybookJob < ActiveJob::Base
4
+ queue_as :ansible
5
+ attr_reader :pid
6
+
7
+ after_perform do |job|
8
+ Foreman::Logging.
9
+ logger('foreman_ansible').
10
+ info('PID for playbook run for'\
11
+ " #{job.arguments.first} #{job.arguments.second}:"\
12
+ " #{pid}")
13
+ end
14
+
15
+ def perform(playbook_path, inventory_path)
16
+ @pid = spawn("ansible-playbook -i #{inventory_path} #{playbook_path}",
17
+ :out => log_file,
18
+ :err => log_file)
19
+ end
20
+
21
+ private
22
+
23
+ def log_file
24
+ "#{::Foreman::Logging.log_directory}/"\
25
+ "#{::Foreman::Logging.config[:filename]}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ # Simple model to store basic info about the Ansible role
2
+ class AnsibleRole < ActiveRecord::Base
3
+ validates :name, :presence => true, :uniqueness => true
4
+ has_many :host_ansible_roles
5
+ has_many_hosts :through => :host_ansible_roles, :dependent => :destroy
6
+ end
@@ -0,0 +1,14 @@
1
+ module ForemanAnsible
2
+ # Relations to make Host::Managed 'have' ansible roles
3
+ module HostManagedExtensions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :host_ansible_roles, :foreign_key => :host_id
8
+ has_many :ansible_roles, :through => :host_ansible_roles,
9
+ :dependent => :destroy
10
+
11
+ attr_accessible :ansible_role_ids, :ansible_roles
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # Join model that hosts the connection between hosts and ansible_roles
2
+ class HostAnsibleRole < ActiveRecord::Base
3
+ audited :associated_with => :host, :allow_mass_assignment => true
4
+ attr_accessible :host_id, :host, :ansible_role_id, :ansible_role
5
+
6
+ belongs_to_host
7
+ belongs_to :ansible_role
8
+
9
+ validates :ansible_role_id, :presence => true,
10
+ :uniqueness => { :scope => :host_id }
11
+ end
@@ -0,0 +1,14 @@
1
+ # Displays Ansible roles tab on Host form
2
+ Deface::Override.new(
3
+ :virtual_path => 'hosts/_form',
4
+ :name => 'ansible_roles_tab',
5
+ :insert_after => 'li.active',
6
+ :partial => 'foreman_ansible/hosts/tab_title'
7
+ )
8
+
9
+ Deface::Override.new(
10
+ :virtual_path => 'hosts/_form',
11
+ :name => 'ansible_roles_tab_content',
12
+ :insert_after => 'div.tab-pane.active',
13
+ :partial => 'foreman_ansible/hosts/tab_content'
14
+ )
@@ -0,0 +1,18 @@
1
+ require 'securerandom'
2
+ module ForemanAnsible
3
+ # Service to list an inventory to be passed to the ansible-playbook binary
4
+ class InventoryCreator
5
+ attr_reader :hosts
6
+
7
+ def initialize(hosts)
8
+ @hosts = hosts
9
+ end
10
+
11
+ def tempfile
12
+ tempfile = Tempfile.new("foreman-#{SecureRandom.uuid}-inventory")
13
+ tempfile.write(hosts.map(&:fqdn).join('\n'))
14
+ tempfile.close
15
+ tempfile
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module ForemanAnsible
2
+ # Service to generate a playbook given roles and a list of hosts
3
+ class PlaybookCreator
4
+ attr_reader :fqdn, :role_names
5
+
6
+ def initialize(fqdn, role_names)
7
+ @fqdn = fqdn
8
+ @role_names = role_names
9
+ end
10
+
11
+ def roles_playbook
12
+ playbook = ['hosts' => fqdn, 'roles' => role_names]
13
+ playbook.to_yaml
14
+ end
15
+
16
+ def roles_tempfile
17
+ tempfile = Tempfile.new("foreman-ansible-#{fqdn}-roles")
18
+ tempfile.write(roles_playbook)
19
+ tempfile.close
20
+ tempfile
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module ForemanAnsible
2
+ # Sugar-coating so that playing a list of roles is easier and
3
+ # more understandable, it just requires a host and it figures out the rest
4
+ class RolePlayer
5
+ attr_reader :host
6
+
7
+ def initialize(host)
8
+ @host = host
9
+ end
10
+
11
+ def play
12
+ return if host.ansible_roles.empty?
13
+ inventory_tempfile = InventoryCreator.new([host]).tempfile
14
+ RunPlaybookJob.new(create_playbook.path,
15
+ inventory_tempfile.path).enqueue
16
+ end
17
+
18
+ private
19
+
20
+ def create_playbook
21
+ PlaybookCreator.new(
22
+ host.fqdn,
23
+ host.ansible_roles.map(&:name)).roles_tempfile
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ module ForemanAnsible
2
+ # Service to import roles from the filesystem.
3
+ # Should be extracted to a gem that both the proxy and Foreman can use.
4
+ class RolesImporter
5
+ class << self
6
+ def import!
7
+ list_roles_in_fs.each do |role_name|
8
+ role = AnsibleRole.new(:name => role_name)
9
+ next if role.save
10
+ Rails.logger.debug("Failed to save role #{role_name}: "\
11
+ "#{role.errors.full_messages.join(', ')}")
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def list_roles_in_fs
18
+ Dir.glob('/etc/ansible/roles/*').map do |path|
19
+ path.split('/').last
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ <div class='tab-pane' id='ansible_roles'>
2
+ <%= multiple_checkboxes f, :ansible_roles, @host, ansible_roles,
3
+ :label => _('Roles') %>
4
+ </div>
@@ -0,0 +1 @@
1
+ <li><a href="#ansible_roles" data-toggle="tab"><%= _('Ansible Roles') %></a></li>
data/config/routes.rb ADDED
@@ -0,0 +1,14 @@
1
+ Rails.application.routes.draw do
2
+ scope :ansible, :path => '/ansible', :as => 'ansible' do
3
+ constraints(:id => /[^\/]+/) do
4
+ resources :hosts, :only => [] do
5
+ member do
6
+ get :play_roles
7
+ end
8
+ collection do
9
+ get :multiple_play_roles
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ class CreateAnsibleRole < ActiveRecord::Migration
2
+ def change
3
+ create_table :ansible_roles do |t|
4
+ t.string :name, :null => false, :limit => 255
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class CreateJoinTableHostsAnsibleRoles < ActiveRecord::Migration
2
+ def change
3
+ create_join_table :ansible_roles, :hosts do |t|
4
+ t.index [:host_id, :ansible_role_id]
5
+ t.index [:ansible_role_id, :host_id]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ class CreateHostAnsibleRoles < ActiveRecord::Migration
2
+ def change
3
+ rename_table :ansible_roles_hosts, :host_ansible_roles
4
+ add_column :host_ansible_roles, :id, :primary_key
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ proxy_feature = Feature.where(:name => 'Ansible').first_or_create
2
+ if proxy_feature.nil? || proxy_feature.errors.any?
3
+ raise "Unable to create proxy feature: #{format_errors proxy_feature}"
4
+ end
@@ -4,6 +4,7 @@ module ForemanAnsible
4
4
  class Engine < ::Rails::Engine
5
5
  engine_name 'foreman_ansible'
6
6
 
7
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
7
8
  config.autoload_paths += Dir["#{config.root}/app/helpers"]
8
9
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
9
10
  config.autoload_paths += Dir["#{config.root}/app/services"]
@@ -11,7 +12,15 @@ module ForemanAnsible
11
12
 
12
13
  initializer 'foreman_ansible.register_plugin', :before => :finisher_hook do
13
14
  Foreman::Plugin.register :foreman_ansible do
14
- requires_foreman '>= 1.9'
15
+ # We need ActiveJob, only available post-1.12 because of Rails 4.2
16
+ requires_foreman '>= 1.12'
17
+ end
18
+ end
19
+
20
+ # Add any db migrations
21
+ initializer 'foreman_remote_execution.load_app_instance_data' do |app|
22
+ ForemanAnsible::Engine.paths['db/migrate'].existent.each do |path|
23
+ app.config.paths['db/migrate'] << path
15
24
  end
16
25
  end
17
26
 
@@ -20,6 +29,10 @@ module ForemanAnsible
20
29
  ::FactImporter.register_fact_importer(:ansible,
21
30
  ForemanAnsible::FactImporter)
22
31
  ::FactParser.register_fact_parser(:ansible, ForemanAnsible::FactParser)
32
+ ::Host::Managed.send(:include, ForemanAnsible::HostManagedExtensions)
33
+ ::HostsHelper.send(:include, ForemanAnsible::HostsHelperExtensions)
34
+ ::HostsController.send(
35
+ :include, ForemanAnsible::Concerns::HostsControllerExtensions)
23
36
  rescue => e
24
37
  Rails.logger "Foreman Ansible: skipping engine hook (#{e})"
25
38
  end
@@ -2,5 +2,5 @@
2
2
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
3
3
  # and detect what version the plugin is running.
4
4
  module ForemanAnsible
5
- VERSION = '0.3'
5
+ VERSION = '1.0'
6
6
  end
@@ -5,7 +5,8 @@ namespace :test do
5
5
  test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
6
6
  t.libs << ['test', test_dir]
7
7
  t.pattern = "#{test_dir}/**/*_test.rb"
8
- t.verbose = true
8
+ t.verbose = false
9
+ t.warning = false
9
10
  end
10
11
  end
11
12
 
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :ansible_role, :class => ForemanAnsible::AnsibleRole do
3
+ sequence(:name) { |n| "ansible_role_#{n}"}
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class HostsControllerExtensionsTest < ActionController::TestCase
4
+ tests ::HostsController
5
+
6
+ setup do
7
+ @role = FactoryGirl.create(:ansible_role)
8
+ end
9
+
10
+ test 'create a host with ansible roles' do
11
+ host = { :name => 'foo',
12
+ :managed => false,
13
+ :ansible_role_ids => [@role.id] }
14
+ post :create, { :host => host },
15
+ set_session_user
16
+ assert_redirected_to host_url(assigns('host'))
17
+ assert assigns('host').ansible_roles, [@role]
18
+ end
19
+
20
+ test 'update a host with ansible roles' do
21
+ host = FactoryGirl.create(:host, :managed => false)
22
+ post :update, { :id => host.id, :ansible_role_ids => [@role.id] },
23
+ set_session_user
24
+ assert_redirected_to host_url(assigns('host'))
25
+ assert assigns('host').ansible_roles, [@role]
26
+ end
27
+
28
+ test 'delete a host with ansible roles' do
29
+ host = FactoryGirl.create(:host, :managed => false,
30
+ :ansible_roles => [@role])
31
+ assert_include @role.hosts, host
32
+ delete :destroy, { :id => host.id }, set_session_user
33
+ assert_redirected_to hosts_url
34
+ assert @role.hosts.empty?
35
+ end
36
+ end
@@ -8,3 +8,7 @@ end
8
8
  def facts_json
9
9
  HashWithIndifferentAccess.new(JSON.parse(sample_facts_file))
10
10
  end
11
+
12
+ plugin_factories_path = File.join(File.dirname(__FILE__), 'factories')
13
+ FactoryGirl.definition_file_paths << plugin_factories_path
14
+ FactoryGirl.reload
@@ -0,0 +1,8 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class AnsibleRoleTest < ActiveSupport::TestCase
4
+ should have_many(:host_ansible_roles)
5
+ should have_many(:hosts).through(:host_ansible_roles).dependent(:destroy)
6
+ should validate_presence_of(:name)
7
+ should validate_uniqueness_of(:name)
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class HostAnsibleRoleTest < ActiveSupport::TestCase
4
+ should belong_to(:host)
5
+ should belong_to(:ansible_role)
6
+ should validate_presence_of(:ansible_role_id)
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -48,14 +48,33 @@ files:
48
48
  - LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
+ - app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb
51
52
  - app/helpers/foreman_ansible/ansible_reports_helper.rb
53
+ - app/helpers/foreman_ansible/ansible_roles_helper.rb
54
+ - app/helpers/foreman_ansible/hosts_helper_extensions.rb
55
+ - app/jobs/foreman_ansible/run_playbook_job.rb
56
+ - app/models/ansible_role.rb
57
+ - app/models/concerns/foreman_ansible/host_managed_extensions.rb
52
58
  - app/models/foreman_ansible/fact_name.rb
59
+ - app/models/host_ansible_role.rb
60
+ - app/overrides/ansible_roles_tab.rb
53
61
  - app/overrides/report_output.rb
54
62
  - app/services/foreman_ansible/fact_importer.rb
55
63
  - app/services/foreman_ansible/fact_parser.rb
56
64
  - app/services/foreman_ansible/fact_sparser.rb
65
+ - app/services/foreman_ansible/inventory_creator.rb
66
+ - app/services/foreman_ansible/playbook_creator.rb
67
+ - app/services/foreman_ansible/role_player.rb
68
+ - app/services/foreman_ansible/roles_importer.rb
57
69
  - app/views/foreman_ansible/config_reports/_ansible.html.erb
58
70
  - app/views/foreman_ansible/config_reports/_output.html.erb
71
+ - app/views/foreman_ansible/hosts/_tab_content.html.erb
72
+ - app/views/foreman_ansible/hosts/_tab_title.html.erb
73
+ - config/routes.rb
74
+ - db/migrate/20160705082036_create_ansible_role.rb
75
+ - db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb
76
+ - db/migrate/20160707195442_create_host_ansible_roles.rb
77
+ - db/seeds.d/62-ansible_proxy_feature.rb
59
78
  - lib/foreman_ansible.rb
60
79
  - lib/foreman_ansible/engine.rb
61
80
  - lib/foreman_ansible/version.rb
@@ -64,12 +83,16 @@ files:
64
83
  - locale/en/foreman_ansible.po
65
84
  - locale/foreman_ansible.pot
66
85
  - locale/gemspec.rb
86
+ - test/factories/ansible_roles.rb
67
87
  - test/fixtures/sample_facts.json
88
+ - test/functional/hosts_controller_test.rb
68
89
  - test/test_plugin_helper.rb
90
+ - test/unit/ansible_role_test.rb
69
91
  - test/unit/fact_importer_test.rb
70
92
  - test/unit/fact_parser_test.rb
71
93
  - test/unit/fact_sparser_test.rb
72
94
  - test/unit/helpers/foreman_ansible/ansible_reports_helper_test.rb
95
+ - test/unit/host_ansible_role_test.rb
73
96
  homepage: https://github.com/theforeman/foreman_ansible
74
97
  licenses:
75
98
  - GPL-3
@@ -96,8 +119,12 @@ specification_version: 4
96
119
  summary: Ansible integration with Foreman (theforeman.org)
97
120
  test_files:
98
121
  - test/fixtures/sample_facts.json
122
+ - test/factories/ansible_roles.rb
123
+ - test/functional/hosts_controller_test.rb
99
124
  - test/test_plugin_helper.rb
100
125
  - test/unit/fact_parser_test.rb
126
+ - test/unit/host_ansible_role_test.rb
127
+ - test/unit/ansible_role_test.rb
101
128
  - test/unit/fact_importer_test.rb
102
129
  - test/unit/fact_sparser_test.rb
103
130
  - test/unit/helpers/foreman_ansible/ansible_reports_helper_test.rb