1

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 

1 Answers1

3

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • hi @coderanger, I didn't override any attributes or sudoers config of `sudo` cookbook but the problem exists when I include it in my cookbook. Thanks for answering. – michaelprog Sep 16 '16 at 07:02
  • Yes, the default config of the `sudo` cookbook is enough to break things. – coderanger Sep 16 '16 at 07:29
  • hi @coderanger, I agree with you. I created a temporary solution by logging-in the virtual machine using `kitchen login` and edit the `sudoers` file just to add the kitchen user. how can I fix it? Thanks. – michaelprog Sep 16 '16 at 11:57
  • hi @coderanger, I fixed it by adding this configuration in `kitchen.yml`. I added above on how to fix it. Thanks. – michaelprog Sep 16 '16 at 12:40