Skip to content

Commit

Permalink
Configure smart_proxy_ansible plugin
Browse files Browse the repository at this point in the history
Closes GH-285
  • Loading branch information
iNecas authored and ekohl committed Sep 15, 2016
1 parent 7e24c97 commit 90a98bb
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
41 changes: 41 additions & 0 deletions manifests/plugin/ansible.pp
@@ -0,0 +1,41 @@
# = Ansible proxy plugin
#
# This class installs Ansible support for Foreman proxy
#
# === Advanced parameters:
#
# $ansible_dir:: Ansible directory to search for available roles
#
# $working_dir:: A directory where the playbooks will be generated.
# A tmp directory will be created when left blank
#
# $enabled:: Enables/disables the plugin
# type:boolean
#
# $listen_on:: Proxy feature listens on https, http, or both
#
class foreman_proxy::plugin::ansible (
$enabled = $::foreman_proxy::plugin::ansible::params::enabled,
$listen_on = $::foreman_proxy::plugin::ansible::params::listen_on,
$ansible_dir = $::foreman_proxy::plugin::ansible::params::ansible_dir,
$working_dir = $::foreman_proxy::plugin::ansible::params::working_dir,
) inherits foreman_proxy::plugin::ansible::params {

validate_bool($enabled)
validate_listen_on($listen_on)
validate_absolute_path($ansible_dir)
if $working_dir {
validate_absolute_path($working_dir)
}

include ::foreman_proxy::plugin::dynflow

foreman_proxy::plugin { 'ansible':
} ->
foreman_proxy::settings_file { 'ansible':
enabled => $enabled,
listen_on => $listen_on,
template_path => 'foreman_proxy/plugin/ansible.yml.erb',
} ~>
Service['smart_proxy_dynflow_core']
}
7 changes: 7 additions & 0 deletions manifests/plugin/ansible/params.pp
@@ -0,0 +1,7 @@
# Ansible proxy default parameters
class foreman_proxy::plugin::ansible::params {
$enabled = true
$listen_on = 'https'
$ansible_dir = '/etc/ansible'
$working_dir = undef
}
45 changes: 45 additions & 0 deletions spec/classes/foreman_proxy__plugin__ansible_spec.rb
@@ -0,0 +1,45 @@
require 'spec_helper'

describe 'foreman_proxy::plugin::ansible' do

let :facts do
on_supported_os['redhat-7-x86_64']
end

describe 'with default settings' do
let :pre_condition do
"include foreman_proxy"
end

it { should contain_foreman_proxy__plugin('dynflow') }

it 'should configure ansible.yml' do
should contain_file('/etc/foreman-proxy/settings.d/ansible.yml').
with_content(/:enabled: https/).
with_content(%r{:ansible_dir: /etc/ansible})
end
end

describe 'with override parameters' do
let :pre_condition do
"include foreman_proxy"
end

let :params do
{
:enabled => true,
:ansible_dir => '/etc/ansible-test',
:working_dir => '/tmp'
}
end

it { should contain_foreman_proxy__plugin('dynflow') }

it 'should configure ansible.yml' do
should contain_file('/etc/foreman-proxy/settings.d/ansible.yml').
with_content(/:enabled: https/).
with_content(%r{:ansible_dir: /etc/ansible-test}).
with_content(%r{:working_dir: /tmp})
end
end
end
8 changes: 8 additions & 0 deletions templates/plugin/ansible.yml.erb
@@ -0,0 +1,8 @@
---
:enabled: <%= @module_enabled %>
:ansible_dir: <%= scope.lookupvar("foreman_proxy::plugin::ansible::ansible_dir") %>
<% if [nil, :undefined, :undef].include?(scope.lookupvar("foreman_proxy::plugin::ansible::working_dir")) -%>
#:working_dir: /var/tmp
<% else -%>
:working_dir: <%= scope.lookupvar("foreman_proxy::plugin::ansible::working_dir") %>
<% end -%>

0 comments on commit 90a98bb

Please sign in to comment.