Raj kumar
Raj kumar

Reputation: 171

"sudo chef-client" failed in Amazon Linux EC2 server

Below is the "chef-client" error message:

It says cookbook apt is missing , but when I check the list of cookbooks in chef server using knife cookbook list , I see the apt cookbook. Please help me. I have deployed apache2 cookbook , now changed the runlist in the chef-client in the node.

13:  service 'apache2' do
14:    supports :status => true
15:    action [:enable, :start]
16:  end
17:  
18:  template '/var/www/html/index.html' do


Running handlers:
[2016-01-25T07:40:17+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-01-25T07:40:17+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 01 seconds
[2016-01-25T07:40:17+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-01-25T07:40:17+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-01-25T07:40:17+00:00] ERROR: Cookbook apt not found. If you're loading apt from another cookbook, make sure you configure the dependency in your metadata
[2016-01-25T07:40:17+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

update :

i could successfully install all the cookbooks in the Test Kitchen using Vagrant,but i could not successfully deploy in the AWS EC2.

below is another example :

   default_guard_interpreter :default
              package_name "php-devel"
              flush_cache {:before=>false, :after=>false}
               declared_type :package
               cookbook_name "php"
               recipe_name "package"
             end


         Running handlers:
 [2016-01-25T09:00:06-05:00] ERROR: Running exception
         handlers Running handlers complete 
[2016-01-25T09:00:06-05:00] ERROR:
         Exception handlers complete Chef Client failed. 0 resources updated in
         16 seconds 
[2016-01-25T09:00:07-05:00] FATAL: Stacktrace dumped to
         /var/chef/cache/chef-stacktrace.out 
[2016-01-25T09:00:07-05:00] FATAL:
         Please provide the contents of the stacktrace.out file if you file a
         bug report 
[2016-01-25T09:00:07-05:00] ERROR: yum_package[php-devel]
         (php::package line 59) had an error: Chef::Exceptions::Package: No
         candidate version available for php-devel 
[2016-01-25T09:00:07-05:00]
         FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited
         unsuccessfully (exit code 1)

update 2: i have successfully installed the chef cookbook "Wordpress" in the AWS EC2 Ubuntu 14.04 instance. But , Failed in the Amazon Linux EC2 and Redhat linux EC2 . So what might be the issue here ? Using Test Kitchen , i could successfully deploy in the CentOS ! But not able to install in Redhat linux and Amazon Linux in the AWS EC2.

    +  DocumentRoot /var/www/wordpress
    +
    +  <Directory /var/www/wordpress>
    +    Options FollowSymLinks
    +    AllowOverride FileInfo Options
    +    Require all granted
    +  </Directory>
    +
    +  <Directory />
    +    Options FollowSymLinks
    +    AllowOverride None
    +  </Directory>
    +
    +  LogLevel info
    +  ErrorLog /var/log/apache2/wordpress-error.log
    +  CustomLog /var/log/apache2/wordpress-access.log combined
    +
    +  RewriteEngine On
    +</VirtualHost>
    - change mode from '' to '0644'
    - change owner from '' to 'root'
    - change group from '' to 'root'
  * execute[a2ensite wordpress.conf] action run
    - execute /usr/sbin/a2ensite wordpress.conf
Recipe: apache2::default
  * service[apache2] action reload
    - reload service service[apache2]

Running handlers:
Running handlers complete
Chef Client finished, 92/168 resources updated in 01 minutes 58 seconds

Upvotes: 0

Views: 955

Answers (1)

zuazo
zuazo

Reputation: 5738

I think you are not using the official apache2 cookbook, but creating your own to learn.

You need to include the apt cookbook as a dependency in your metadata.rb:

# metadata.rb
depends 'apt', '~> 2.9'

Please, note that, other than to learn chef, you should use the official httpd or apache2 cookbooks rather than creating your own.

Update:

Chef::Exceptions::Package: No candidate version available for php-devel

The php cookbook you are using is trying to install the php-devel package. But this package does not exist on the distribution you are using on EC2.

Try to use an EC2 AMI with the same OS and distribution version you are testing with test-kitchen.

The php cookbook version you are using seems to not support the OS you are using on EC2.

Update 2:

Maybe some of the cookbooks you are using do not support Amazon Linux or the other distributions you are trying to use.

Anyway, you can use kitchen-ec2 gem to test your cookbooks on Amazon Linux before deploying them.

.kitchen.yml example:

platforms:
- name: amazon-20XX.YY.ZZ
  driver:
    name: ec2
    image_id: ami-XXXXX # The AMI id of Amazon Linux
    instance_type: t1.micro
  transport:
    username: ec2-user

Upvotes: 2

Related Questions