From 90a98bb918802e7dd155518b8298108c66ca88d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ne=C4=8Das?= Date: Wed, 14 Sep 2016 21:00:28 +0200 Subject: [PATCH] Configure smart_proxy_ansible plugin Closes GH-285 --- manifests/plugin/ansible.pp | 41 +++++++++++++++++ manifests/plugin/ansible/params.pp | 7 +++ .../foreman_proxy__plugin__ansible_spec.rb | 45 +++++++++++++++++++ templates/plugin/ansible.yml.erb | 8 ++++ 4 files changed, 101 insertions(+) create mode 100644 manifests/plugin/ansible.pp create mode 100644 manifests/plugin/ansible/params.pp create mode 100644 spec/classes/foreman_proxy__plugin__ansible_spec.rb create mode 100644 templates/plugin/ansible.yml.erb diff --git a/manifests/plugin/ansible.pp b/manifests/plugin/ansible.pp new file mode 100644 index 00000000..3abe81b9 --- /dev/null +++ b/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'] +} diff --git a/manifests/plugin/ansible/params.pp b/manifests/plugin/ansible/params.pp new file mode 100644 index 00000000..ff4aa819 --- /dev/null +++ b/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 +} diff --git a/spec/classes/foreman_proxy__plugin__ansible_spec.rb b/spec/classes/foreman_proxy__plugin__ansible_spec.rb new file mode 100644 index 00000000..19e59c71 --- /dev/null +++ b/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 diff --git a/templates/plugin/ansible.yml.erb b/templates/plugin/ansible.yml.erb new file mode 100644 index 00000000..6ed927cc --- /dev/null +++ b/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 -%>