diff --git a/manifests/init.pp b/manifests/init.pp index fc8c4e1..7f8696d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,19 +1,6 @@ # == Class: ssh # -# Manage ssh client and server. -# -# Sample usage: -# # Push authorized key "root_for_userX" and remove key "root_for_userY" with hiera -# -# ssh::keys: -# root_for_userX: -# ensure: present -# user: root -# type: dsa -# key: AAAA...== -# root_for_userY: -# ensure: absent -# user: root +# Manage ssh client and server # class ssh ( $packages = 'USE_DEFAULTS', diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 66ab8c8..9e8ecd0 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -35,6 +35,10 @@ describe 'ssh' do should contain_file('ssh_config').with_content(/^# This file is being maintained by Puppet.\n# DO NOT EDIT\n\n# \$OpenBSD: ssh_config,v 1.21 2005\/12\/06 22:38:27 reyk Exp \$/) } + it { should_not contain_file('ssh_config').with_content(/^\s*ForwardAgent$/) } + it { should_not contain_file('ssh_config').with_content(/^\s*ForwardX11$/) } + it { should_not contain_file('ssh_config').with_content(/^\s*ServerAliveInterval$/) } + it { should contain_file('sshd_config').with({ 'ensure' => 'file', @@ -100,6 +104,39 @@ describe 'ssh' do } end + context 'with optional params used in ssh_config set on osfamily RedHat' do + let :facts do + { + :fqdn => 'monkey.example.com', + :osfamily => 'RedHat', + :sshrsakey => 'AAAAB3NzaC1yc2EAAAABIwAAAQEArGElx46pD6NNnlxVaTbp0ZJMgBKCmbTCT3RaeCk0ZUJtQ8wkcwTtqIXmmiuFsynUT0DFSd8UIodnBOPqitimmooAVAiAi30TtJVzADfPScMiUnBJKZajIBkEMkwUcqsfh630jyBvLPE/kyQcxbEeGtbu1DG3monkeymanOBW1AKc5o+cJLXcInLnbowMG7NXzujT3BRYn/9s5vtT1V9cuZJs4XLRXQ50NluxJI7sVfRPVvQI9EMbTS4AFBXUej3yfgaLSV+nPZC/lmJ2gR4t/tKvMFF9m16f8IcZKK7o0rK7v81G/tREbOT5YhcKLK+0wBfR6RsmHzwy4EddZloyLQ==' + } + end + let :params do + { + :ssh_config_forward_agent => 'yes', + :ssh_config_forward_x11 => 'yes', + :ssh_config_server_alive_interval => '300', + } + end + + it { + should contain_file('ssh_config').with({ + 'ensure' => 'file', + 'path' => '/etc/ssh/ssh_config', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'require' => 'Package[ssh_packages]', + }) + } + + it { should contain_file('ssh_config').with_content(/^# This file is being maintained by Puppet.\n# DO NOT EDIT\n\n# \$OpenBSD: ssh_config,v 1.21 2005\/12\/06 22:38:27 reyk Exp \$/) } + it { should contain_file('ssh_config').with_content(/^ ForwardAgent yes$/) } + it { should contain_file('ssh_config').with_content(/^ ForwardX11 yes$/) } + it { should contain_file('ssh_config').with_content(/^ ServerAliveInterval 300$/) } + end + context 'with manage_root_ssh_config set to \'true\' on valid osfamily' do let :facts do { diff --git a/templates/ssh_config.erb b/templates/ssh_config.erb index e5ab70f..743a15b 100644 --- a/templates/ssh_config.erb +++ b/templates/ssh_config.erb @@ -50,13 +50,13 @@ Host * # to the original X11 display. As virtually no X11 client supports the untrusted # mode correctly we set this to yes. ForwardX11Trusted yes -<% if @ssh_config_forward_agent -%> +<% if @ssh_config_forward_agent != nil -%> ForwardAgent <%= @ssh_config_forward_agent %> <% end -%> -<% if @ssh_config_forward_x11 -%> +<% if @ssh_config_forward_x11 != nil -%> ForwardX11 <%= @ssh_config_forward_x11 %> <% end -%> -<% if @ssh_config_server_alive_interval -%> +<% if @ssh_config_server_alive_interval != nil -%> ServerAliveInterval <%= @ssh_config_server_alive_interval %> <% end -%> # Send locale-related environment variables