Search code examples
chef-infrasudochef-recipecookbooktest-kitchen

Kitchen test failed: Sudo requires a password, please configure it on default-centos-67


This is content of default.rb recipe of my cookbook.

include_recipe 'sudo'
include_recipe 'chef-vault'

group "#{node['cookbook']['group']}" do 
  action    :create
  append    true
  system    false
end

user 'user' do
    supports    :manage_home => false 
    home        nil
    system      false
    password    "HASH_PASSWORD"
    gid         "#{node['cookbook']['group']}"
    shell       '/bin/bash'
    action      :create
end

This is also the content of kitchen.yml.

    driver:
      name: docker
      use_sudo: false

    provisioner:
      name: chef_zero

    verifier:
      name: inspec

    platforms:
      - name: centos-6.7

    suites:
     - name: default
       data_bags_path: "test/integration/default/data_bags"
       encrypted_data_bag_secret_key_path: "test/integration/default/encrypted_data_bag_secret"
       run_list:
        - recipe[rise-users::default]
       attributes: 

This is the kitchen test that I created.

control "mycookbook-1.0" do
   impact 1.0
   title "myCookbook users packages and configuration files"
   desc "packages and configuration files that should exist on all  servers"

   describe user('user') do
     it { should exist }
   end
end

I executed the kitchen test command and got this eror.

>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [Sudo failed: Sudo requires a password, please configure it.] on default-centos-67
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

I updated the kitchen.yml just to configure it since sudo requires a password but unfortunately it doesn't work.

I fixed it by updating theattributes in kitchen.yml.

 attributes: 
    authorization: 
        sudo: 
            users: ['kitchen'] 
            passwordless: true 
            include_sudoers_d: true 

Solution

  • This usually means somewhere in a cookbook you are testing, you are changing the sudoers config such that the kitchen user doesn't have nopasswd sudo. You need to either not do that, or when running under Test Kitchen make sure you re-create the entry for the kitchen user.