Sha256: 6215e59f1db15f9d59216c0da10de093f8e94424e84b4b18a1eb78f59121331e

Contents?: true

Size: 879 Bytes

Versions: 1

Compression:

Stored size: 879 Bytes

Contents

module ForemanAnsible
  # Relations to make Hostgroup 'have' ansible roles
  module HostgroupExtensions
    extend ActiveSupport::Concern

    included do
      has_many :hostgroup_ansible_roles, :foreign_key => :hostgroup_id
      has_many :ansible_roles, :through => :hostgroup_ansible_roles,
                               :dependent => :destroy
      include ForemanAnsible::HasManyAnsibleRoles
      audit_associations :ansible_roles

      def inherited_ansible_roles
        ancestors.reduce([]) do |roles, hostgroup|
          roles + hostgroup.ansible_roles
        end.uniq
      end

      def inherited_and_own_ansible_roles
        path.reduce([]) do |roles, hostgroup|
          roles + hostgroup.ansible_roles
        end.uniq
      end

      def host_ansible_roles
        hosts.all.includes(:ansible_roles).flat_map(&:ansible_roles)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_ansible-2.2.4 app/models/concerns/foreman_ansible/hostgroup_extensions.rb