Sha256: 9b61a10e87ee1533b8d16b921f2bf82782880a9f1b33d6f3d88066c5b74a8ecc
Contents?: true
Size: 1.14 KB
Versions: 36
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true 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 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 # includes also roles of all assigned hosts, useful to determine if # at least one host in this hostgroup has some ansible role assigned # either directly or through hostgroup def all_ansible_roles (ansible_roles + inherited_ansible_roles + host_ansible_roles).uniq end end end end
Version data entries
36 entries across 36 versions & 1 rubygems