Sha256: 3dff762c747ab39de89c17395d4b8422a3d828f07f87604c7555d16a01d3b77e

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module ForemanAnsible
  # Relations to make Host::Managed 'have' ansible roles
  module HostManagedExtensions
    extend ActiveSupport::Concern

    included do
      has_many :host_ansible_roles, :foreign_key => :host_id
      has_many :ansible_roles, :through => :host_ansible_roles,
                               :dependent => :destroy
      scoped_search :relation => :ansible_roles, :on => :name,
                    :complete_value => true, :rename => :role,
                    :only_explicit => true

      before_provision :play_ansible_roles
      include ForemanAnsible::HasManyAnsibleRoles

      def inherited_ansible_roles
        return [] unless hostgroup
        hostgroup.all_ansible_roles
      end

      def play_ansible_roles
        return unless ansible_roles.present? || inherited_ansible_roles.present?
        task = ::ForemanTasks.async_task(
          ::Actions::ForemanAnsible::PlayHostRoles,
          self,
          ::ForemanAnsible::ProxySelector.new,
          :timeout => Setting['ansible_post_provision_timeout']
        )
        logger.info("Task for Ansible roles on #{self} before_provision: "\
                    "#{Rails.application.routes.url_helpers.task_path(task)}.")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_ansible-1.5.2 app/models/concerns/foreman_ansible/host_managed_extensions.rb
foreman_ansible-1.5.1 app/models/concerns/foreman_ansible/host_managed_extensions.rb
foreman_ansible-1.5.0 app/models/concerns/foreman_ansible/host_managed_extensions.rb