From 3485f6cffe0d125c2b42106357019c7b4c82e9bf Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 25 Feb 2021 12:22:14 +0900 Subject: [PATCH 1/2] Ubuntu 20.04 and Chef 16 support Drop `umask` in `known_hosts`, because it lead to a fatal error `no implicit conversion from nil to integer`. And it had actually no purpose because either the file always already exist. It either exists before Chef runs, or we create it ourselve via the `file` resource with proper `mode` just before using `execute`. `known_hosts` also better detect presence of host in config file for CentOS where `ssh-keygen` does not print out human readable message including "Host found". `config` now supports config file that contains the `Include` keyword before any `Host` keyword, as is seen in Ubuntu 20.04. --- .kitchen.yml | 5 ++--- libraries/ssh_config_helpers.rb | 2 +- providers/known_hosts.rb | 4 +--- spec/provider_tests/config_spec.rb | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index da77029..d02c599 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,16 +7,15 @@ provisioner: driver_plugin: vagrant driver_config: - require_chef_omnibus: '12.19' #'latest' customize: cpus: 2 memory: 2048 cpuexecutioncap: 75 platforms: - - name: ubuntu-12.04 + - name: ubuntu-20.04 driver_config: - box: 'ubuntu/precise64' + box: 'ubuntu/focal64' run_list: - recipe[apt] - name: centos-7.2 diff --git a/libraries/ssh_config_helpers.rb b/libraries/ssh_config_helpers.rb index c546360..d7e03ea 100644 --- a/libraries/ssh_config_helpers.rb +++ b/libraries/ssh_config_helpers.rb @@ -23,7 +23,7 @@ def parse_file(path) # rubocop:disable Style/CyclomaticComplexity next if check_name && (name = check_name) && (entries[name] = {}) key, entry = parse_line(line) - next unless entry + next unless entry && name entries[name][key] = entry end entries diff --git a/providers/known_hosts.rb b/providers/known_hosts.rb index 2c694a1..85bed5f 100644 --- a/providers/known_hosts.rb +++ b/providers/known_hosts.rb @@ -28,7 +28,6 @@ def whyrun_supported? execute "add known_host entry for #{new_resource.host}" do command "echo '#{new_resource.key}' >> #{new_resource.path}" user new_resource.user if new_resource.user - umask new_resource.user ? 0o077 : 0o022 end end end @@ -38,7 +37,6 @@ def whyrun_supported? execute "remove known_host entry for #{new_resource.host}" do command "ssh-keygen -R #{Shellwords.escape(new_resource.host)} -f #{new_resource.path}" user new_resource.user if new_resource.user - umask new_resource.user ? 0o077 : 0o022 end end @@ -80,7 +78,7 @@ def load_current_resource cmd = if new_resource.key.nil? "ssh-keygen #{new_resource.hashed ? '-H ' : ''} -F #{Shellwords.escape(matching_host)} "\ - "-f #{new_resource.path} | grep -F 'Host #{matching_host} found'" + "-f #{new_resource.path} | grep ." else "grep -F '#{new_resource.key}' '#{new_resource.path}'" end diff --git a/spec/provider_tests/config_spec.rb b/spec/provider_tests/config_spec.rb index 1d0fdc4..d77883b 100644 --- a/spec/provider_tests/config_spec.rb +++ b/spec/provider_tests/config_spec.rb @@ -3,7 +3,7 @@ # rubocop:disable Metrics/BlockLength describe 'ssh_config resource' do let(:chef_run) do - runner = ChefSpec::SoloRunner.new(:platform => 'ubuntu', :version => '12.04', :step_into => 'ssh_config') + runner = ChefSpec::SoloRunner.new(:platform => 'ubuntu', :version => '20.04', :step_into => 'ssh_config') runner.converge('ssh_test::config') end From 3077e02e7c7db6f7cced68d457a46a4d037bf9ce Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Tue, 2 Mar 2021 17:17:38 +0900 Subject: [PATCH 2/2] mv .kitchen.yml kitchen.yml #7907 Because it's new Chef best-practice --- .kitchen.yml => kitchen.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .kitchen.yml => kitchen.yml (100%) diff --git a/.kitchen.yml b/kitchen.yml similarity index 100% rename from .kitchen.yml rename to kitchen.yml