Skip to content

Commit

Permalink
Fixes #30398 - Add DSL docs for ansible (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jul 20, 2020
1 parent 344333d commit 250d970
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/ansible_role.rb
Expand Up @@ -28,6 +28,12 @@ class AnsibleRole < ApplicationRecord
scoped_search :relation => :hostgroups,
:on => :name, :rename => :hostgroup, :only_explicit => true

apipie :class, "A class representing #{model_name.human} object" do
name 'Ansible role'
refs 'AnsibleRole'
sections only: %w[all additional]
property :name, String, desc: 'Returns name of the ansible role'
end
# Methods to be allowed in any template with safemode enabled
class Jail < Safemode::Jail
allow :name
Expand Down
Expand Up @@ -67,6 +67,11 @@ def import_host(*args)

module Host
class Managed
apipie :class do
property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited'
property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles assigned to the host'
property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns inherited ansible roles assigned to the host'
end
# Methods to be allowed in any template with safemode enabled
class Jail < Safemode::Jail
allow :all_ansible_roles, :ansible_roles, :inherited_ansible_roles
Expand Down
11 changes: 11 additions & 0 deletions app/services/foreman_ansible/renderer_methods.rb
Expand Up @@ -4,7 +4,18 @@ module ForemanAnsible
# Macro to fetch RH Insights plan playbook
module RendererMethods
extend ActiveSupport::Concern
extend ApipieDSL::Module

apipie :class, 'Macros related to Ansible playbooks' do
name 'Ansible'
sections only: %w[all jobs]
end

apipie :method, 'Returns Insights maintenance plan for host' do
required :plan_id, String, desc: 'The playbook for the rule coming from insights'
optional :organization_id, Integer, desc: 'The Foreman organization associated with the Insights account', default: 'Current organization ID'
returns String, desc: 'Insights maintenance plan for host'
end
def insights_remediation(plan_id, organization_id = Organization.current.id)
return "$INSIGHTS_REMEDIATION[#{plan_id}, #{organization_id}]" if preview?

Expand Down
4 changes: 4 additions & 0 deletions lib/foreman_ansible/register.rb
Expand Up @@ -109,6 +109,10 @@
apipie_documented_controllers [
"#{ForemanAnsible::Engine.root}/app/controllers/api/v2/*.rb"
]
ApipieDSL.configuration.dsl_classes_matchers += [
"#{ForemanAnsible::Engine.root}/app/models/*.rb",
"#{ForemanAnsible::Engine.root}/app/services/foreman_ansible/*.rb"
]

register_info_provider ForemanAnsible::AnsibleInfo

Expand Down

0 comments on commit 250d970

Please sign in to comment.