Kitchen verify causes "sudo failed and requires TTY" when trying to use inspec

I am trying to use chef inspec to test my cookbook changes. I am testing the installation of newrelic package and service from my recipe. When i tried to run kitchen verify it fails with Sudo failed: Sudo requires a TTY. can any one help me to know what could be wrong here that might not allowing me to verify test cases. Thanks

Test Directory Path - test/integration/default/inspec/default_spec.rb

describe service(‘nrsysmond’) do
it { should be_enabled }
it { should be_running }
end

describe package(‘newrelic-sysmond’) do
it { should be_installed }
end

-----> Verifying <default-rhel-67>... Detected alternative framework tests forinspecSearch/Users/abc/code/domain_chef/newrelic-chef/cookbooks/newrelic/test/integration/default/inspec` for tests

------Exception-------
Class: Kitchen::ActionFailed
Message: Failed to complete #verify action: [Sudo failed: Sudo requires a TTY. Please see the README on how to configure sudo to allow for non-interactive usage.]
`

Thanks @darknight It looks like this issue is related to https://github.com/chef/train/issues/60 Redhat/Centos have a strange default config for sudo. The simplest solution is to run a helper cookbook to properly configure the sudo configuration e.g. /etc/sudoers.d/chef:

chef ALL=(root) NOPASSWD: ALL
Defaults!ALL !requiretty

Here is an example that configures the system properly from a cookbook: https://github.com/chef-cookbooks/cis-el7-l1-hardening/blob/master/recipes/enable_sudo_no_tty.rb

1 Like

Thanks @chris-rock for the info. I was able to use the above values in a config file and was able to run kitchen verify using Inspec.