Giter Club home page Giter Club logo

chef-client's Introduction

Chef Client Cookbook

Build Status Cookbook Version

This cookbook is used to configure a system to run the Chef Infra Client.

Deprecation

This cookbook is no longer under active maintenance. The functionality previously provided here is now built into Chef Infra Client itself making it easier to configure Chef Infra Client without the need for external dependencies.

See these built-in resources for managing client.rb configuration and setting up Chef Infra Client to run on a schedule:

What about older Chef Infra Client Releases

If you're using an Infra Client release before the above resources shipped, you can keep using this cookbook without issue. Just keep in mind that at some point in the future changes to Chef Infra Client may cause this cookbook to stop working. We believe the built-in resoures offer a more powerful configuration options for users. The approach offered by these resources also align with our own best practices and we'd highly suggest moving towards those resources for configuring your Chef Infra Client.

The new resources are missing x, y, or z

If there's af feature missing from the new resources please do let us know at https://github.com/chef/chef/issues. We will not be replicating all functionality of this cookbook, but we are interested in hearing what the community needs to manage their systems.

Requirements

Platforms

  • AIX 6+
  • Clear Linux
  • Debian
  • Fedora
  • FreeBSD
  • macOS
  • openSUSE
  • SLES 12+
  • RHEL
  • Solaris 10+
  • Ubuntu
  • Windows

Chef

  • Chef 13.0+

Cookbooks

  • cron 2.0+
  • logrotate 1.9.0+

See USAGE.

Resources

The chef-client cookbook provides several resources for setting up Chef Infra Client to run on a schedule. When possible these resources should be used instead of the legacy attributes / recipes as these same resources will be included in Chef Infra Client 16+ out of the box.

chef_client_scheduled_task

The chef_client_scheduled_task resource setups up Chef Infra Client to run as a scheduled task on Windows. You can use this resource directly in any of your own recipes. Using this resource to configure Chef Infra Client running as a scheduled task allows you to control where you store the user credentials instead of storing them as node attributes. This is useful if you want to store these credentials in an encrypted databag or other secrets store.

Actions

  • :add
  • :remove

Properties

  • user - The username to run the task as. default: 'System'
  • password The password of the user to run the task as if not using the System user
  • frequency - Frequency with which to run the task (e.g., 'hourly', 'daily', etc.) Default is 'minute'
  • frequency_modifier Numeric value to go with the scheduled task frequency - default: '30'
  • start_time The start time for the task in HH:mm format (ex: 14:00). If the frequency is minute default start time will be Time.now plus the frequency_modifier number of minutes.
  • start_date - The start date for the task in m:d:Y format (ex: 12/17/2017). nil by default and isn't necessary if you're running a regular interval.
  • splay - A random number of seconds between 0 and X to add to interval. default: '300'
  • config_directory - The path to the Chef config directory. default: 'C:/chef'
  • log_file_name - The name of the log file. default: 'client.log'
  • log_directory - The path to the Chef log directory. default: 'CONFIG_DIRECTORY/log'
  • chef_binary_path - The path to the chef-client binary. default: 'C:/opscode/chef/bin/chef-client'
  • daemon_options - An optional array of extra options to pass to the chef-client
  • task_name - The name of the scheduled task. This allows for multiple chef_client_scheduled_task resources when it is used directly like in a wrapper cookbook. default: 'chef-client'

chef_client_cron

The chef_client_cron resource sets up Chef Infra Client to run as a cron job using a cron.d configuration file on Linux hosts or a job in /etc/crontab for other Unix operating systems. You can use this resource directly in any of your own recipes.

Actions

  • :add
  • :remove

Properties

  • user - The username to run the task as. default: 'root'
  • minute - The minute that Chef Infra Client will run as a cron task. default: '0,30' (every 30 minutes)
  • hour - The hour that Chef Infra Client will run as a cron task. default: '*'
  • day - The day that Chef Infra Client will run as a cron task. default: '*'
  • month - The month that Chef Infra Client will run as a cron task. default: '*'
  • weekday - The weekday that Chef Infra Client will run as a cron task. default: '*'
  • comment - A comment to add to the cron file.
  • mailto - The e-mail address to e-mail any cron task failures to.
  • job_name - The name of the cron task to create. This allows you to have schedules with different options if necessary. default: 'chef-client'
  • splay - A random number of seconds between 0 and X to add to interval. default: '300'
  • environment - A hash of environment variables to pass to chef-client's execution (e.g. SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt chef-client)
  • config_directory - The path to the Chef config directory. default: '/etc/chef/'
  • log_file_name - The name of the log file. default: 'client.log'
  • log_directory - The path to the Chef log directory. default: '/var/log/chef' on *nix or '/Library/Logs/Chef' on macOS
  • append_log_file - Whether to append to the log. Default: true chef-client output.
  • chef_binary_path - The path to the chef-client binary. default: '/opt/chef/bin/chef-client'
  • daemon_options - An optional array of extra command line options to pass to the chef-client

chef_client_trusted_certificate

The chef_client_trusted_certificate allows you to add a certificate to Chef Infra Client's set of trusted certificates. This is helpful when adding internal certificates for systems that the Chef Infra Client will later need to communicate with using SSL. You can use this resource directly in any of your own recipes.

Actions

  • :add
  • :remove

Properties

  • cert_name - The name on disk for the cert file. If not specified the resource name will be used (and .pem appended if necessary)
  • certificate - The text content of the certificate file

Examples

chef_client_trusted_certificate 'self-signed.badssl.com' do
  certificate <<~CERT
  -----BEGIN CERTIFICATE-----
  MIIDeTCCAmGgAwIBAgIJAPziuikCTox4MA0GCSqGSIb3DQEBCwUAMGIxCzAJBgNV
  BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNp
  c2NvMQ8wDQYDVQQKDAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTAeFw0x
  OTEwMDkyMzQxNTJaFw0yMTEwMDgyMzQxNTJaMGIxCzAJBgNVBAYTAlVTMRMwEQYD
  VQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMQ8wDQYDVQQK
  DAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEB
  BQADggEPADCCAQoCggEBAMIE7PiM7gTCs9hQ1XBYzJMY61yoaEmwIrX5lZ6xKyx2
  PmzAS2BMTOqytMAPgLaw+XLJhgL5XEFdEyt/ccRLvOmULlA3pmccYYz2QULFRtMW
  hyefdOsKnRFSJiFzbIRMeVXk0WvoBj1IFVKtsyjbqv9u/2CVSndrOfEk0TG23U3A
  xPxTuW1CrbV8/q71FdIzSOciccfCFHpsKOo3St/qbLVytH5aohbcabFXRNsKEqve
  ww9HdFxBIuGa+RuT5q0iBikusbpJHAwnnqP7i/dAcgCskgjZjFeEU4EFy+b+a1SY
  QCeFxxC7c3DvaRhBB0VVfPlkPz0sw6l865MaTIbRyoUCAwEAAaMyMDAwCQYDVR0T
  BAIwADAjBgNVHREEHDAaggwqLmJhZHNzbC5jb22CCmJhZHNzbC5jb20wDQYJKoZI
  hvcNAQELBQADggEBAGlwCdbPxflZfYOaukZGCaxYK6gpincX4Lla4Ui2WdeQxE95
  w7fChXvP3YkE3UYUE7mupZ0eg4ZILr/A0e7JQDsgIu/SRTUE0domCKgPZ8v99k3A
  vka4LpLK51jHJJK7EFgo3ca2nldd97GM0MU41xHFk8qaK1tWJkfrrfcGwDJ4GQPI
  iLlm6i0yHq1Qg1RypAXJy5dTlRXlCLd8ufWhhiwW0W75Va5AEnJuqpQrKwl3KQVe
  wGj67WWRgLfSr+4QG1mNvCZb2CkjZWmxkGPuoP40/y7Yu5OFqxP5tAjj4YixCYTW
  EVA0pmzIzgBg+JIe3PdRy27T0asgQW/F4TY61Yk=
  -----END CERTIFICATE-----
  CERT
end

Attributes

The following attributes affect the behavior of the chef-client program when running as a service through one of the service recipes, or in cron with the cron recipe, or are used in the recipes for various settings that require flexibility.

  • node['chef_client']['interval'] - Sets Chef::Config[:interval] via command-line option for number of seconds between chef-client daemon runs. Default 1800.
  • node['chef_client']['splay'] - Sets Chef::Config[:splay] via command-line option for a random amount of seconds to add to interval. On windows, this value is used for the scheduled task's random delay. Default 300.
  • node['chef_client']['log_file'] - Sets the file name used to store chef-client logs. Default "client.log".
  • node['chef_client']['log_dir'] - Sets directory used to store chef-client logs. Default "/var/log/chef".
  • node['chef_client']['log_rotation']['options'] - Set options to logrotation of chef-client log file. Default ['compress'].
  • node['chef_client']['log_rotation']['prerotate'] - Set prerotate action for chef-client logrotation. Default to nil.
  • node['chef_client']['log_rotation']['postrotate'] - Set postrotate action for chef-client logrotation. Default to chef-client service reload depending on init system. It should be empty to skip reloading chef-client service in case if node['chef_client']['systemd']['timer'] is true.
  • node['chef_client']['conf_dir'] - Sets directory used via command-line option to a location where chef-client search for the client config file . Default "/etc/chef".
  • node['chef_client']['bin'] - Sets the full path to the chef-client binary. Mainly used to set a specific path if multiple versions of chef-client exist on a system or the bin has been installed in a non-sane path. Default "/opt/chef/bin/chef-client".
  • node['chef_client']['ca_cert_path'] - Sets the full path to the PEM-encoded certificate trust store used by chef-client when daemonized. If not set, default values are used.
  • node['chef_client']['cron']['minute'] - The minute that chef-client will run as a cron task. See cron recipe
  • node['chef_client']['cron']['hour'] - The hour that chef-client will run as a cron task. See cron recipe
  • node['chef_client']['cron']['weekday'] - The weekday that chef-client will run as a cron task. See cron recipe
  • node['chef_client']['cron']['environment_variables'] - Environment variables to pass to chef-client's execution (e.g. SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt chef-client)
  • node['chef_client']['cron']['log_file'] - Location to capture the log output of chef-client during the chef run.
  • node['chef_client']['cron']['append_log'] - Whether to append to the log. Default: false chef-client output.
  • node['chef_client']['cron']['use_cron_d'] - If true, use the cron_d resource. If false (default), use the cron resource built-in to Chef.
  • node['chef_client']['cron']['mailto'] - If set, MAILTO env variable is set for cron definition
  • node['chef_client']['cron']['priority'] - If set, defines the scheduling priority for the chef-client process. MUST be a value between -20 and 19. ONLY applies to *nix-style operating systems.
  • node['chef_client']['reload_config'] - If true, reload Chef config of current Chef run when client.rb template changes (defaults to true)
  • node['chef_client']['daemon_options'] - An array of additional options to pass to the chef-client service, empty by default, and must be an array if specified.
  • node['chef_client']['systemd']['timer'] - If true, uses systemd timer to run chef frequently instead of chef-client daemon mode (defaults to false). This only works on platforms where systemd is installed and used.
  • node['chef_client']['systemd']['timeout'] - If configured, sets the systemd timeout. This might be useful to avoid stalled chef runs in the systemd timer setup.
  • node['chef_client']['systemd']['restart'] - The string to use for systemd Restart= value when not running as a timer. Defaults to always. Other possible options: no, on-success, on-failure, on-abnormal, on-watchdog, on-abort.
  • node['chef_client']['systemd']['killmode'] - If configured, the string to use for the systemd KillMode= value. This determines how PIDs spawned by the chef-client process are handled when chef-client PID stops. Options: control-group, process, mixed, none. Systemd defaults to control-group when this is not specified. More information can be found on the systemd.kill man page.
  • node['chef_client']['task']['frequency'] - Frequency with which to run the chef-client scheduled task (e.g., 'hourly', 'daily', etc.) Default is 'minute'.
  • node['chef_client']['task']['frequency_modifier'] - Numeric value to go with the scheduled task frequency. Default is node['chef_client']['interval'].to_i / 60
  • node['chef_client']['task']['start_time'] - The start time for the task in HH:mm format (ex: 14:00). If the frequency is minute default start time will be Time.now plus the frequency_modifier number of minutes.
  • node['chef_client']['task']['start_date'] - The start date for the task in m:d:Y format (ex: 12/17/2017). nil by default and isn't necessary if you're running a regular interval.
  • node['chef_client']['task']['user'] - The user the scheduled task will run as, defaults to 'SYSTEM'.
  • node['chef_client']['task']['password'] - The password for the user the scheduled task will run as, defaults to nil because the default user, 'SYSTEM', does not need a password.
  • node['chef_client']['task']['name'] - The name of the scheduled task, defaults to chef-client.

The following attributes are set on a per-platform basis, see the attributes/default.rb file for default values.

  • node['chef_client']['init_style'] - Sets up the client service based on the style of init system to use. Default is based on platform and falls back to 'none'. See service recipes.

  • node['chef_client']['run_path'] - Directory location where chef-client should write the PID file. Default based on platform, falls back to "/var/run".

  • node['chef_client']['file_cache_path'] - Directory location for Chef::Config[:file_cache_path] where chef-client will cache various files. Default is unset as it causes problems on first chef runs. The default location is typically "/var/cache/cache" but could be different based on the platform. Use this attribute at your own risk.

  • node['chef_client']['file_backup_path'] - Directory location for Chef::Config[:file_backup_path] where chef-client will backup templates and cookbook files. Default is based on platform, falls back to "/var/chef/backup".

  • node['chef_client']['file_staging_uses_destdir'] - How file staging (via temporary files) is done. When true, temporary files are created in the directory in which files will reside. When false, temporary files are created under ENV['TMP']. When set to :auto it creates them in the destination directory, and falls back to the ENV['TMP'] directory when that is not possible. default value: chef-client default. This cookbook makes use of attribute-driven configuration with this attribute. See USAGE for examples.

  • node['chef_client']['launchd_mode'] - (only for macOS) If set to 'daemon', runs chef-client with -d and -s options; defaults to 'interval'.

  • node['chef_client']['launchd_working_dir'] - (only for macOS) Sets the working directory for the launchd user (generally root); defaults to /var/root.

  • node['chef_client']['launchd_self-update'] - (only for macOS) Determines whether chef-client should attempt to :restart itself when changes are made to the launchd plist during converge. Note that the current implementation of macosx_service :restart unloads the daemon, which stops the current chef-client run and requires an external process to resume the service. Defaults to false.

  • When chef_client['log_file'] is set and running on a logrotate supported platform (debian, rhel, fedora family), use the following attributes to tune log rotation.

    • node['chef_client']['logrotate']['rotate'] - Number of rotated logs to keep on disk, default 12.
    • node['chef_client']['logrotate']['frequency'] - How often to rotate chef client logs, default weekly.
  • node['chef_client']['config'] - A hash of Chef::Config keys and their values, rendered dynamically in /etc/chef/client.rb.

  • node['chef_client']['load_gems'] - Hash of gems to load into chef via the client.rb file

  • node['ohai']['disabled_plugins'] - An array of ohai plugins to disable, empty by default, and must be an array if specified. Ohai 6 plugins should be specified as a string (ie. "dmi"). Ohai 7+ plugins should be specified as a symbol within quotation marks (ie. ":Passwd").

  • node['ohai']['optional_plugins'] - An array of optional ohai plugins to enable, empty by default, and must be an array if specified. Ohai 6 plugins should be specified as a string (ie. "dmi"). Ohai 7+ plugins should be specified as a symbol within quotation marks (ie. ":Passwd").

  • node['ohai']['plugin_path'] - An additional path to load Ohai plugins from. Necessary if you use the ohai_plugin resource in the Ohai cookbook to install your own ohai plugins.

Chef Client Config

For the most current information about Chef Client configuration, read the documentation..

  • node['chef_client']['chef_license'] - Set to 'accept' or 'accept-no-persist' to accept the license before upgrading to Chef 15.

  • node['chef_client']['config']['chef_server_url'] - The URL for the Chef server.

  • node['chef_client']['config']['validation_client_name'] - The name of the chef-validator key that is used by the chef-client to access the Chef server during the initial chef-client run.

  • node['chef_client']['config']['verbose_logging'] - Set the log level. Options: true, nil, and false. When this is set to false, notifications about individual resources being processed are suppressed (and are output at the :info logging level). Setting this to false can be useful when a chef-client is run as a daemon. Default value: nil.

  • node['chef_client']['config']['rubygems_url'] - The location to source rubygems. It can be set to a string or array of strings for URIs to set as rubygems sources. This allows individuals to setup an internal mirror of rubygems for "airgapped" environments. Default value: https://www.rubygems.org.

  • See USAGE for how to set handlers with the config attribute.

Recipes

This section describes the recipes in the cookbook and how to use them in your environment.

config

Sets up the /etc/chef/client.rb config file from a template and reloads the configuration for the current chef-client run.

See USAGE for more information on how the configuration is rendered with attributes.

service recipes

The chef-client::service recipe includes one of the chef-client::INIT_STYLE_service recipes based on the attribute, node['chef_client']['init_style']. The individual service recipes can be included directly, too. For example, to use the init scripts, on a node or role's run list:

recipe[chef-client::init_service]

Use this recipe on systems that should have a chef-client daemon running, such as when Knife bootstrap was used to install Chef on a new system.

  • init - uses the init script included in this cookbook, supported on debian and redhat family distributions.
  • launchd - sets up the service under launchd, supported on macOS
  • bsd - prints a message about how to update BSD systems to enable the chef-client service.
  • systemd - sets up the service under systemd. Supported on systemd based distros.

default

Includes the chef-client::service recipe by default on *nix platforms and the task recipe for Windows hosts.

delete_validation

Use this recipe to delete the validation certificate (default /etc/chef/validation.pem) when using a chef-client after the client has been validated and authorized to connect to the server.

cron

Use this recipe to run chef-client as a cron job rather than as a service. The cron job runs after random delay that is between 0 and 90 seconds to ensure that the chef-clients don't attempt to connect to the chef-server at the exact same time. You should set node['chef_client']['init_style'] = 'none' when you use this mode but it is not required.

task

Use this recipe to run chef-client on Windows nodes as a scheduled task. Without modifying attributes the scheduled task will run 30 minutes after the recipe runs, with each chef run rescheduling the run 30 minutes in the future. By default the job runs as the system user. The time period between runs can be modified with the default['chef_client']['task']['frequency_modifier'] attribute and the user can be changed with the default['chef_client']['task']['user'] and default['chef_client']['task']['password'] attributes.

Usage

Use the recipes as described above to configure your systems to run Chef as a service via cron / scheduled task or one of the service management systems supported by the recipes.

The chef-client::config recipe is only required with init style init (default setting for the attribute on debian/redhat family platforms, because the init script doesn't include the pid_file option which is set in the config.

If you wish to accept the Chef license before upgrading to Chef 15 you must use the chef-client::config recipe or set the chef_license value in your config manually. See Accepting the Chef license for more details or other ways to accept the license.

The config recipe is used to dynamically generate the /etc/chef/client.rb config file. The template walks all attributes in node['chef_client']['config'] and writes them out as key:value pairs. The key should be the configuration directive. For example, the following attributes (in a role):

default_attributes(
  "chef_client" => {
    "config" => {
      "ssl_verify_mode" => ":verify_peer",
      "client_fork" => true
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

chef_server_url "https://api.chef.io/organizations/MYORG"
validation_client_name "MYORG-validator"
ssl_verify_mode :verify_peer
node_name "config-ubuntu-1204"
client_fork true

The chef_server_url, node_name and validation_client_name are set by default in the attributes file from Chef::Config. They are presumed to come from the knife bootstrap command when setting up a new node for Chef. To set the node name to the default value (the node['fqdn'] attribute), it can be set false. Be careful when setting this or the Server URL, as those values may already exist.

As another example, to set HTTP proxy configuration settings. By default Chef will not use a proxy.

default_attributes(
  "chef_client" => {
    "config" => {
      "http_proxy" => "http://proxy.mycorp.com:3128",
      "https_proxy" => "http://proxy.mycorp.com:3128",
      "http_proxy_user" => "my_username",
      "http_proxy_pass" => "Awe_some_Pass_Word!",
      "no_proxy" => "*.vmware.com,10.*"
    }
  }
)

Special Behavior

Because attributes are strings and the /etc/chef/client.rb can use settings that are not string, such as symbols, some configuration attributes have resulting lines with special behavior:

  • the audit_mode, log_level, and ssl_verify_mode attributes are converted to symbols. The attribute need not include an initial colon. For example:
default_attributes(
  "chef_client" => {
    "config" => {
      "ssl_verify_mode" => ":verify_peer",
      "log_level" => "debug"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

ssl_verify_mode :verify_peer
log_level :debug
  • the log_level setting can be either a string representing a file path or one of the symbols STDOUT, STDERR, :syslog, and :win_evt. If the log_level attribute is a string suggestive of one of these symbols, the resulting configuration line will use the symbol. For example,
default_attributes(
  "chef_client" => {
    "config" => {
      "log_location" => "STDOUT"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

log_location STDOUT

and

default_attributes(
  "chef_client" => {
    "config" => {
      "log_location" => ":syslog"
    }
  }
)

will render the following configuration (/etc/chef/client.rb):

log_location :syslog

The strings "syslog" and "win_evt" will become the symbols :syslog and :win_evt regardless of whether they have an initial colon.

Configuration Includes

The /etc/chef/client.rb file will include all the configuration files in /etc/chef/client.d/*.rb. To create custom configuration, simply render a file resource with file (and the content parameter), template, remote_file, or cookbook_file. For example, in your own cookbook that requires custom Chef client configuration, create the following cookbook_file resource:

chef_gem 'syslog-logger'

cookbook_file "/etc/chef/client.d/myconfig.rb" do
  source "myconfig.rb"
  mode '0644'
  notifies :create, "ruby_block[reload_client_config]"
end

include_recipe 'chef-client::config'

Then create files/default/myconfig.rb with the configuration content you want. For example, if you wish to create a configuration to log to syslog:

require 'syslog-logger'
require 'syslog'

Logger::Syslog.class_eval do
  attr_accessor :sync, :formatter
end

log_location Chef::Log::Syslog.new('chef-client', ::Syslog::LOG_DAEMON)

On Windows:

log_location Chef::Log::WinEvt.new

Requiring Gems

Use the load_gems attribute to install gems that need to be required in the client.rb. This attribute should be a hash. The gem will also be installed with chef_gem. For example, suppose we want to use a Chef Handler Gem, chef-handler-updated-resources, which is used in the next heading. Set the attributes, e.g., in a role:

default_attributes(
  "chef_client" => {
    "load_gems" => {
      "chef-handler-updated-resources" => {
        "require_name" => "chef/handler/updated_resources",
        "version" => "0.1"
      }
    }
  }
)

Each key in load_gems is the name of a gem. Each gem hash can have two keys, the require_name which is the string that will be require'd in /etc/chef/client.rb, and version which is the version of the gem to install. If the version is not specified, the latest version will be installed.

The above example will render the following in /etc/chef/client.rb:

["chef/handler/updated_resources"].each do |lib|
  begin
    require lib
  rescue LoadError
    Chef::Log.warn "Failed to load #{lib}. This should be resolved after a chef run."
  end
end

Start, Report, Exception Handlers

To dynamically render configuration for Start, Report, or Exception handlers, set the following attributes in the config attributes:

  • start_handlers
  • report_handlers
  • exception_handlers

This is an alternative to using the chef_handler cookbook.

Each of these attributes must be an array of hashes. The hash has two keys, class (a string), and arguments (an array). For example, to use the report handler in the Requiring Gems section:

default_attributes(
  "chef_client" => {
    "config" => {
      "report_handlers" => [
        {"class" => "SimpleReport::UpdatedResources", "arguments" => []}
      ]
    }
  }
)

If the handler you're using has an initialize method that takes arguments, then pass each one as a member of the array. Otherwise, leave it blank as above.

This will render the following in /etc/chef/client.rb.

report_handlers << SimpleReport::UpdatedResources.new()

Launchd

On macOS and macOS Server, the default service implementation is "launchd".

Since launchd can run a service in interval mode, by default chef-client is not started in daemon mode like on Debian or Ubuntu. Keep this in mind when you look at your process list and check for a running chef process! If you wish to run chef-client in daemon mode, set attribute chef_client.launchd_mode to "daemon".

Installing and updating chef-client

This cookbook does not handle updating the chef-client, as that's out of the cookbook's current scope. To sensibly manage updates of the chef-client's install, we refer you to:

License

Copyright: 2010-2020, Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

chef-client's People

Contributors

americanhanko avatar chrisroberts avatar ctramnitz avatar cwebberops avatar dcrosta avatar dheerajd-msys avatar glensc avatar gregsymons avatar iennae avatar jtimberman avatar juliandunn avatar kamaradclimber avatar lamont-granquist avatar mbrukman avatar miketheman avatar mwrock avatar nathwill avatar ramereth avatar retr0h avatar rikzg avatar ryanfrantz avatar schisamo avatar scotthain avatar sethvargo avatar stevendanna avatar tas50 avatar tduffield avatar twirrim avatar williamsjj avatar xorimabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chef-client's Issues

Ruby WMI is no longer shipped with Chef

We've switched Chef to use wmi-lite in 11.14.2, so we need to stop using WMI in the chef-client cookbook.

chef/chef#1749

DEBUG: Re-raising exception: NameError - uninitialized constant Opscode::ChefClient::Helpers::WMI
C:/chef/cache/cookbooks/chef-client/libraries/helpers.rb:44:in `root_owner'

Chef server 12 runs under 'opscode' user, not 'chef_server'

This dir_owner helper will return 'chef_server' and thus the config recipe will fail every time.

Chef::Exceptions::UserIDNotFound: template[/etc/chef/client.rb] (chef-client::config line 73) had an error: Chef::Exceptions::UserIDNotFound: cannot determine user id for 'chef_server', does the user exist on this system?

https://github.com/opscode-cookbooks/chef-client/blob/bf1dbbc749c92315784b17bac796ed858a256f5d/recipes/config.rb#L70-L85

https://github.com/opscode-cookbooks/chef-client/blob/bf1dbbc749c92315784b17bac796ed858a256f5d/libraries/helpers.rb#L60-L66

https://github.com/opscode-cookbooks/chef-client/blob/bf1dbbc749c92315784b17bac796ed858a256f5d/libraries/helpers.rb#L26-L28

Windows Deploy gives Errno::EIO: Input/output error - CreateProcessW

Using windows 8.1 to run chef to deploy git repo I get the error below when git is called:

ErFATAL: Errno::EIO: deploy[C:\dir] (ts::default line 16) had an error: Errno::EIO: Input/output error - CreateProcessW

I've checked to make sure git is on the path and I've replicated this on several 8.1 machines. I think the issue is that windows is expecting .exe/.bat/.cmd on the end of the git command.
The only way I've managed to get around it is use a custom provider see this stackoverflow question.

The recipe is:

deploy "#{node['ts']['installdir']}" do
  repo 'https://myinternalrepo/repo.git'
  action :deploy
end

and the top of the stacktrace is:

Errno::EIO: deploy[C:\ts] (ts::default line 13) had an error: Errno::EIO: Input/output error - CreateProcessW
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.4.0-x86-mingw32/lib/mixlib/shellout/windows/core_ext.rb:346:in `create'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.4.0-x86-mingw32/lib/mixlib/shellout/windows.rb:86:in `run_command'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.4.0-x86-mingw32/lib/mixlib/shellout.rb:227:in `run_command'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.14.2-x86-mingw32/lib/chef/mixin/shell_out.rb:37:in `shell_out'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.14.2-x86-mingw32/lib/chef/mixin/shell_out.rb:42:in `shell_out!'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.14.2-x86-mingw32/lib/chef/provider/git.rb:250:in `remote_resolve_reference'
C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.14.2-x86-mingw32/lib/chef/provider/git.rb:229:in `target_revision'

any help debugging this further would be appreciated - I'm not sure if this a problem with my setup or with chef...

Need to be able to override client.rb values

https://tickets.opscode.com/browse/CHEF-4304

Seeing as running chef-client remotely can't override values of 'log_location' and 'loglevel'. there needs to be attributes set for loglevel and log_rotation in order to override them to STDOUT and info for example. running chef client remotely on a windows node that has client.rb log_location set to c:\chef\log\client.log, I don't get the full chef-client output to STDOUT. This is problematic in that I have to manually create a secondary client.rb config file with log_location set to STDOUT and loglevel set to INFO.

find_chef_client can't locate Chef 12 chef-client.bat

I'm guessing from helpers.rb:112 that the chef-client executable used to be a .exe. It appears that it is now a .bat in 12.0.3 of chef.

This causes 4.2.4 to break with the message Could not locate the chef-client bin in any known path. Please set the proper path by overriding the node['chef_client']['bin'] attribute. when using the task recipe.

It looks like issue #244 also breaks the task as well?

Support for yum 'virtual provider', specifically 'mysql' on RHEL 7

With RHEL7 MariaDB became the default MySQL package when the 'mysql' package is required. (Reference on work that went on in Fedora -- http://fedoraproject.org/wiki/Features/ReplaceMySQLwithMariaDB).

When executing chef-client with a basic recipe of 'package "mysql"' in local mode, this is the results on RHEL 7.0:

[ec2-user@ip-172-31-14-129 test]$ sudo chef-client -l warn -L /tmp/chef-client-mysqltest-warn.output -z -o mysqltest
[2014-09-23T16:27:16-04:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 11.16.0
resolving cookbooks for run list: ["mysqltest"]
Synchronizing Cookbooks:
  - mysqltest
Compiling Cookbooks...
Converging 1 resources
Recipe: mysqltest::default
  * package[mysql] action install
    * No version specified, and no candidate version available for mysql
    ================================================================================
    Error executing action `install` on resource 'package[mysql]'
    ================================================================================

    Chef::Exceptions::Package
    -------------------------
    No version specified, and no candidate version available for mysql

    Resource Declaration:
    ---------------------
    # In /root/.chef/local-mode-cache/cache/cookbooks/mysqltest/recipes/default.rb

      1: package "mysql"

    Compiled Resource:
    ------------------
    # Declared in /root/.chef/local-mode-cache/cache/cookbooks/mysqltest/recipes/default.rb:1:in `from_file'

    package("mysql") do
      action :install
      retries 0
      retry_delay 2
      guard_interpreter :default
      package_name "mysql"
      timeout 900
      cookbook_name "mysqltest"
      recipe_name "default"
    end


Running handlers:
Running handlers complete
Chef Client failed. 0 resources updated in 8.849940817 seconds

Yum commands showing how 'mysql' is provided:

[ec2-user@ip-172-31-14-129 test]$ sudo yum provides mysql
Loaded plugins: amazon-id, rhui-lb
1:mariadb-5.5.35-3.el7.x86_64 : A community developed branch of MySQL
Repo        : rhui-REGION-rhel-server-releases
Matched from:
Provides    : mysql = 1:5.5.35-3.el7



1:mariadb-5.5.37-1.el7_0.x86_64 : A community developed branch of MySQL
Repo        : rhui-REGION-rhel-server-releases
Matched from:
Provides    : mysql = 1:5.5.37-1.el7_0

It looks like it is resolved via the virtual provider feature in Yum as shown here:

[ec2-user@ip-172-31-14-129 test]$ sudo yum -d 10 install mysql
Not loading "rhnplugin" plugin, as it is disabled
Loading "amazon-id" plugin
Not loading "product-id" plugin, as it is disabled
Loading "rhui-lb" plugin
Not loading "subscription-manager" plugin, as it is disabled
Config time: 0.012
Yum version: 3.4.3
rpmdb time: 0.000
Setting up Package Sacks
mirrorlist: https://rhui2-cds01.us-west-1.aws.ce.redhat.com/pulp/mirror/rhui-client-config/rhel/server/7/x86_64/os
mirrorlist: https://rhui2-cds01.us-west-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel/rhui/server/7/7Server/x86_64/debug
mirrorlist: https://rhui2-cds01.us-west-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel/rhui/server/7/7Server/x86_64/os
mirrorlist: https://rhui2-cds01.us-west-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel/rhui/server/7/7Server/x86_64/source/SRPMS
pkgsack time: 0.250
Checking for virtual provide or file-provide for mysql
Obs Init time: 0.052
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.37-1.el7_0 will be installed

Cookbook doesn't seem to pick up bootstrap'd "environment"

I'm trying to set a client's environment during bootstrap, and when running the chef-client cookbook I would expect to see this environment in the generated /etc/chef/client.rb (similar to how the chef_server_url shows up there). Furthermore the README says this should be the recommended way of setting the environment:

node['chef_client']['environment'] - Set the node's environment directly (e.g., knife bootstrap -E), as it makes it easier to move nodes to different environments.

However looking at this cookbook's default attributes, it doesn't seem to pick up environment:

# We only set these by default because this is what comes from `knife
# bootstrap` (the best way to install Chef Client on managed nodes).
#
# Users can add other configuration options through attributes in
# their favorite way (role, 'site' cookbooks, etc).
default['chef_client']['config'] = {
  'chef_server_url' => Chef::Config[:chef_server_url],
  'validation_client_name' => Chef::Config[:validation_client_name],
  'node_name' => Chef::Config[:node_name] == node['fqdn'] ? false : Chef::Config[:node_name]
}

if Chef::Config.has_key?(:client_fork)
  default['chef_client']['config']['client_fork'] = true
end

Wouldn't it make sense to add "environment" under the default['chef_client']['config'] so it picks it up from bootstrap? Right now I'm stuck having to populate it with my wrapper cookbook around chef_client, which makes moving to another environment difficult...

Thanks!

ignore_failure not ignoring failure

I have an execute resource that will fail on the first ever run, so I did :

ignore_failure true

But it's failing with a Mixlib::ShellOut::ShellCommandFailed
and I can see that it's in the compiled resource as it says:

==> default: ignore_failure true

in the output.

So why is the chef run being terminated when it should just ignore the error and carry on?

EOF errors when downloading cookbooks on Windows

This issue is still happening: https://tickets.opscode.com/browse/CHEF-3303

Repro steps: create a host at Rackspace cloud using knife-rackspace. Cookbooks download once correctly. Make a change to a cookbook, upload to hosted chef.

Subsequent chef runs fail with an EOF error. It seems that the connection is closed by ngx_openresty. Sometimes deleting cache/cookbooks/* helps. Sometimes changing a cookbook's version number and re-uploading helps. Sometimes deleting client.pem and deleting the node helps.

In some cases, the only fix is to blow away the VM and start over. Is there a team assigned to making sure Chef works on Windows? Because this is a total showstopper.

test-kitchen polluting client.rb

It's taking force-logger and putting in the client.rb. Won't run unless it's force_logger

{"chef_client":{"config":{"force-logger":"True"}},"run_list":["recipe[cb-base]"]}

chef-client will not stay running

When including the chef-client cookbook in a manual chef-client run, the service stops when using init init_style on Ubuntu 12.04 and Chef 11.12.8. Upstart works fine.

Scenario:

  • Vanilla Ubuntu 12.04 install, with Chef installed, but init scripts not installed.
  • Chef-client #1 started with run-list "recipe[chef-client]".
  • Recipe starts chef-client as a service (client #2).
  • Client #2 waits for client #1 to finish.
  • Client #1 updates /etc/init.d/chef-client template, and triggers chef-client service restart.
  • Client #2 receives SIGTERM, but waits to shutdown gracefully.
  • Chef-client #3 starts, and immediately exits, due to Client #2 already running.
  • Finally chef-client #1 finishes run, and chef-client #2 starts its run
  • Client #2 ensures that service is running, which it is
  • Client #2 finishes run, and gracefully stops

Result:

  • No chef-clients running

Package resource : Support non-EN locale in Chef 12

Ohai Chefs !

Just wanted to report a bug when using a simple package ressource :

Vagrant precise VM :

~# cat /etc/issue
Ubuntu 12.04.4 LTS

~# chef-apply -v
Chef: 12.0.3

~# locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
~# echo 'package "ntp"' > /tmp/test.rb && chef-apply /tmp/test.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * apt_package[ntp] action install
    - install version 1:4.2.6.p3+dfsg-1ubuntu3.1 of package ntp

Now just change locale to fr_FR :

~# locale
LANG=fr_FR.UTF-8
LANGUAGE=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=fr_FR.UTF-8
~# echo 'package "ntp"' > /tmp/test.rb && chef-apply /tmp/test.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * apt_package[ntp] action install
    * No version specified, and no candidate version available for ntp
    ================================================================================
    Error executing action `install` on resource 'apt_package[ntp]'
    ================================================================================

    Chef::Exceptions::Package
    -------------------------
    No version specified, and no candidate version available for ntp

    Resource Declaration:
    ---------------------
    # In /tmp/test.rb

      1: package "ntp"

    Compiled Resource:
    ------------------
    # Declared in /tmp/test.rb:1:in `run_chef_recipe'

    apt_package("ntp") do
      action :install
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      package_name "ntp"
      timeout 900
      declared_type :package
      cookbook_name "(chef-apply cookbook)"
      recipe_name "(chef-apply recipe)"
    end

[2014-12-22T13:48:19+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-12-22T13:48:19+00:00] FATAL: Chef::Exceptions::Package: apt_package[ntp] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error: Chef::Exceptions::Package: No version specified, and no candidate version available for ntp

Same conf with chef 11 :

~# chef-apply -v
Chef: 11.16.4

~# echo 'package "ntp"' > /tmp/test.rb && chef-apply /tmp/test.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * package[ntp] action install
    - install version 1:4.2.6.p3+dfsg-1ubuntu3.1 of package ntp

All we can say about this issue :

  • package ressource seems to have a dependency to a specific (en) locale in Chef 12 (for some output parsing i guess)
  • It affects Ubuntu (debian & OS based on yum not tested yet)
  • Same behaviour with Ubuntu 14.04 and more
  • This was not blocking in Chef 11 and less.

So is it possible to support non-EN locale or create a workaround to force EN locale inside Chef ?
It would be great for all Chefs around the world.

Thanks for all !

No 3.6.0 Changelog

@cwebberOps FYI.
I never know if the ChangeLog is updated before a tag/release, or after. Something in me says it should be before.

Dont reload chef-client service when using cron + logrotate

Hi, we decide to use cron mode instead of daemon because when you change client.rb chef-client tries to restart himself causing to end the actual execution but not starting the service anymore.

In example:

[2015-02-25T09:25:36+00:00] INFO: template[/etc/init.d/chef-client] sending restart action to service[chef-client] (delayed)
[2015-02-25T09:25:36+00:00] INFO: Processing service[chef-client] action restart (chef-client::init_service line 32)
[2015-02-25T09:25:37+00:00] INFO: SIGTERM received, exiting gracefully
[2015-02-25T09:25:44+00:00] FATAL: Chef is already running pid 6227
[2015-02-25T09:25:44+00:00] INFO: service[chef-client] restarted

When using the cron.rb recipe, we still want to have logrotate feature, but it still try to reload the daemon, it makes no sense.

It should be a way to not use postrotate when using cron, i.e. set cronas the init_style, but the case inside attribute file, makes impossible to properly override at time the init_style attribute, to make the case match the right option.

In the mean while we are fixing this on our wrapper cookbook attributes:

default['chef_client']['log_rotation']['postrotate'] = ''

But if we have mixed strategies on our servers (i.e. some of them with cron , a coule of them as service...) that is not a good idea.

Derived Attributes (Beyond the First) Non-Functional in Chef 12+

See: sous-chefs/iis#117

Validated that the 11.x Chef clients work fine, and the issue is present only in 12+ environments. Using the IIS cookbook for example.

Within the cookbook attribute file: iis/attributes/default.rb

This is currently defined:
default['iis']['home'] = "#{ENV['WINDIR']}\\System32\\inetsrv"
default['iis']['conf_dir'] = "#{iis['home']}\\config"
default['iis']['pubroot'] = "#{ENV['SYSTEMDRIVE']}\\inetpub"
default['iis']['docroot'] = "#{iis['pubroot']}\\wwwroot"
default['iis']['log_dir'] = "#{iis['pubroot']}\\logs\\LogFiles"
default['iis']['cache_dir'] = "#{iis['pubroot']}\\temp"

As of chef 12 only the first derived attribute is properly calculated. Printing out the values within a run is enough to see the issue:
DEBUG: default['iis']['home'] = C:\Windows\System32\inetsrv
DEBUG: default['iis']['conf_dir'] = C:\Windows\System32\inetsrv\config
DEBUG: default['iis']['pubroot'] = C:\inetpub
DEBUG: default['iis']['docroot'] = \wwwroot
DEBUG: default['iis']['log_dir'] = \logs\LogFiles
DEBUG: default['iis']['cache_dir'] = \temp

You can see that only the first attribute is properly calculated be reversing the order of declaration and running again:
default['iis']['pubroot'] = "#{ENV['SYSTEMDRIVE']}\\inetpub"
default['iis']['docroot'] = "#{iis['pubroot']}\\wwwroot"
default['iis']['log_dir'] = "#{iis['pubroot']}\\logs\\LogFiles"
default['iis']['cache_dir'] = "#{iis['pubroot']}\\temp"
default['iis']['home'] = "#{ENV['WINDIR']}\\System32\\inetsrv"
default['iis']['conf_dir'] = "#{iis['home']}\\config"

In this scenario only iis[home] will be empty.

If you fully declare the attributes as below it works in other recipes:
default['iis']['home'] = "#{ENV['WINDIR']}\\System32\\inetsrv"
default['iis']['conf_dir'] = "#{ENV['WINDIR']}\\System32\\inetsrv\\config"
default['iis']['pubroot'] = "#{ENV['SYSTEMDRIVE']}\\inetpub"
default['iis']['docroot'] = "#{ENV['SYSTEMDRIVE']}\\inetpub\\wwwroot"
default['iis']['log_dir'] = "#{ENV['SYSTEMDRIVE']}\\inetpub\\logs\\LogFiles"
default['iis']['cache_dir'] = "#{ENV['SYSTEMDRIVE']}\\inetpub\\temp

windows errors

Hi;

I'm trying to run chef-client on windows 2012 and getting the following errors, can you please assist?

Thanks
Ali.

10.214.0.29 ================================================================================
10.214.0.29 Recipe Compile Error in c:/chef/cache/cookbooks/chef-client/recipes/default.rb
10.214.0.29 ================================================================================
10.214.0.29
10.214.0.29 NoMethodError
10.214.0.29 -------------
10.214.0.29 undefined method Name' for nil:NilClass 10.214.0.29 10.214.0.29 Cookbook Trace: 10.214.0.29 --------------- 10.214.0.29 c:/chef/cache/cookbooks/chef-client/libraries/helpers.rb:45:inroot_owner'
10.214.0.29 c:/chef/cache/cookbooks/chef-client/libraries/helpers.rb:55:in dir_owner' 10.214.0.29 c:/chef/cache/cookbooks/chef-client/libraries/helpers.rb:80:increate_directories'
10.214.0.29 c:/chef/cache/cookbooks/chef-client/recipes/windows_service.rb:31:in from_file' 10.214.0.29 c:/chef/cache/cookbooks/chef-client/recipes/service.rb:43:infrom_file'
10.214.0.29 c:/chef/cache/cookbooks/chef-client/recipes/default.rb:20:in from_file' 10.214.0.29 10.214.0.29 Relevant File Content: 10.214.0.29 ---------------------- 10.214.0.29 c:/chef/cache/cookbooks/chef-client/libraries/helpers.rb: 10.214.0.29 10.214.0.29 38: node.recipe?('chef-server') || system('which chef-server > /dev/null 2>&1') || system('which chef-server-ctl > /dev/null 2>&1') 10.214.0.29 39: end 10.214.0.29 40: end 10.214.0.29 41: 10.214.0.29 42: def root_owner 10.214.0.29 43: if ['windows'].include?(node['platform']) 10.214.0.29 44: adminAccount=WMI::Win32_UserAccount.find(:first,:conditions => "sid like 'S-1-5-21-%-500' and LocalAccount=True") 10.214.0.29 45>> adminAccount.Name 10.214.0.29 46: else 10.214.0.29 47: 'root' 10.214.0.29 48: end 10.214.0.29 49: end 10.214.0.29 50: 10.214.0.29 51: def dir_owner 10.214.0.29 52: if chef_server? 10.214.0.29 53: chef_server_user 10.214.0.29 54: else 10.214.0.29 10.214.0.29 [2014-08-22T10:46:18+00:00] ERROR: Running exception handlers 10.214.0.29 [2014-08-22T10:46:18+00:00] ERROR: Exception handlers complete 10.214.0.29 [2014-08-22T10:46:18+00:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out 10.214.0.29 [2014-08-22T10:46:18+00:00] FATAL: NoMethodError: undefined methodName' for nil:NilClass

chef-client to run as a user context

Some organizations require that chef be run under a user context rather than root. Obviously this poses some challenges. We've used and tested chef-client 3.5.2 with server client version 11.12 and had no issues, however with the introduction of server client 11.14, it looks like it is breaking due to permissions issues and a variety of other issues. Is there any way to make the client work completely in a user context? Enterprise support recommended I try chef-client 3.7 with 11.14 system client, however it is still failing.

Thanks

New update to cron cookbook validation breaks cron_d support in chef-client

After uploading the new cron cookbook the chef-client cookbook fails with the following error when configured with the following attributes

attributes/default

normal[:chef_client] = {
  :init_style   => "none",
  :cron => { :use_cron_d => true,
             :minute     => "00",
             :hour       => "19",
  },
}


Error

  * cron_d[chef-client] action create

    ================================================================================
    Error executing action `create` on resource 'cron_d[chef-client]'
    ================================================================================

    Chef::Exceptions::ValidationFailed
    ----------------------------------
    Option month's value * should be a valid month spec!

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/cron/providers/d.rb:46:in `block (2 levels) in class_from_file'
    /var/chef/cache/cookbooks/cron/providers/d.rb:36:in `block in class_from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/chef-client/recipes/cron.rb

     88:   cron_d 'chef-client' do
     89:     minute  node['chef_client']['cron']['minute']
     90:     hour    node['chef_client']['cron']['hour']
     91:     path    node['chef_client']['cron']['path'] if node['chef_client']['cron']['path']
     92:     mailto  node['chef_client']['cron']['mailto'] if node['chef_client']['cron']['mailto']
     93:     user    'root'
     94:     cmd = ''
     94:     cmd = ''
     95:     cmd << "/bin/sleep #{sleep_time}; " if sleep_time
     96:     cmd << "#{env} #{client_bin} > #{log_file} 2>&1"
     97:     command cmd
     98:   end
     99: else

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/chef-client/recipes/cron.rb:88:in `from_file'

    cron_d("chef-client") do
      action :create
      retries 0
      retry_delay 2
      guard_interpreter :default
      cookbook_name "chef-client"
      recipe_name "cron"
      minute "00"
      hour "23"
      user "root"
      command "/bin/sleep 44;  /usr/bin/chef-client > /dev/null 2>&1"
      cookbook "cron"
      day "*"
    end


Running handlers:
[2014-09-08T20:00:30-07:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-08T20:00:30-07:00] ERROR: Exception handlers complete
[2014-09-08T20:00:30-07:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 1 resources updated in 19.588783447 seconds
[2014-09-08T20:00:30-07:00] ERROR: cron_d[chef-client] (chef-client::cron line 88) had an error: Chef::Exceptions::ValidationFailed: Option month's value * should be a valid month s
pec!
[2014-09-08T20:00:31-07:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

ability to set chef_client.config.file_atomic_updates attrib

The chef-client should be able to set all it;s attrib dynamically from node[chef_client.config] array. I have a need to set file_atomic_update to false from an .kitchen.yml spec. - as an example.

is that possible or that is really missing?

Setting node["chef_client"]["interval"] seems to be ignored for Windows service

I installed chef-client 12.0.3 via bootstrap onto a Windows 8.1 machine. I used the default chef-client recipe to install the windows chef-client service. I'm trying to set the interval for the service to run to 5 mins.

I have a base role set for the windows node:

name "base"
description "Base role"
run_list "recipe[chef-client]"
default_attributes 
override_attributes "chef_client" => { "interval" => "300" }

The chef-client windows service gets installed correctly but it runs at the default of 1800 seconds. I've tried a few different ways of setting the attribute but nothing seems to budge it from the default.

The documentation (https://github.com/opscode-cookbooks/chef-client#attributes) says:

The following attributes affect the behavior of the chef-client program when running as a service through one of the service recipes, or in cron with the cron recipe, or are used in the recipes for various settings that require flexibility.

  • node["chef_client"]["interval"] - Sets Chef::Config[:interval] via command-line option for number of seconds between chef-client daemon runs. Default 1800.

I've looked through the source code of the chef-client recipe and executable but can't find how the interval is set via command-line option when using the windows service recipe. Do I have to set the interval attribute myself in client.rb?

Invalid ruby files in cookbook: chef-client (3.6.0)

I can not upload this cookbook to my chef server:

/usr/bin/berks:23:in `load'
/usr/bin/berks:23:in `<main>'
Ridley::SandboxResource crashed!
Ridley::Errors::CookbookSyntaxError: Invalid ruby files in cookbook: chef-client (3.6.0).
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ridley-1.5.3/lib/ridley/chef/cookbook.rb:175:in `validate'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ridley-1.5.3/lib/ridley/resources/cookbook_resource.rb:201:in `upload'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:67:in `dispatch'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks/task_thread.rb:21:in `block in create'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/internal_pool.rb:59:in `call'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/internal_pool.rb:59:in `block in create'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `call'
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'

chef-client recipe clones resources warnings

The helper method create_directories is called by almost all recipe:

$ grep create_directories recipes/*
recipes/arch_service.rb:create_directories
recipes/bluepill_service.rb:create_directories
recipes/bsd_service.rb:create_directories
recipes/config.rb:create_directories
recipes/cron.rb:create_directories
recipes/daemontools_service.rb:create_directories
recipes/init_service.rb:create_directories
recipes/launchd_service.rb:create_directories
recipes/runit_service.rb:create_directories
recipes/smf_service.rb:create_directories
recipes/systemd_service.rb:create_directories
recipes/task.rb:create_directories
recipes/upstart_service.rb:create_directories
recipes/windows_service.rb:  create_directories
recipes/winsw_service.rb:create_directories

and once we have multiple such recipes in runlist, it will then raise warnings about resource cloning:

[2014-07-10T05:33:37+00:00] WARN: Cloning resource attributes for directory[/var/run/chef] from prior resource (CHEF-3694)
[2014-07-10T05:33:37+00:00] WARN: Previous directory[/var/run/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'
[2014-07-10T05:33:37+00:00] WARN: Current  directory[/var/run/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'
[2014-07-10T05:33:37+00:00] WARN: Cloning resource attributes for directory[/var/cache/chef] from prior resource (CHEF-3694)
[2014-07-10T05:33:37+00:00] WARN: Previous directory[/var/cache/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'
[2014-07-10T05:33:37+00:00] WARN: Current  directory[/var/cache/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'
[2014-07-10T05:33:37+00:00] WARN: Cloning resource attributes for directory[/var/lib/chef] from prior resource (CHEF-3694)
[2014-07-10T05:33:37+00:00] WARN: Previous directory[/var/lib/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'
[2014-07-10T05:33:37+00:00] WARN: Current  directory[/var/lib/chef]: /var/chef/cache/cookbooks/chef-client/libraries/helpers.rb:83:in `block in create_directories'

IMO keep it in config.rb would be sufficient. Or if you do like it, it would be better to keep it in a common recipe, and then include the common recipe in other recipes.

metadata.rb file missing from chef-client-4.2.0.tar.gz

Hey,

So I'm trying to upgrade chef-client cookbook within my repo from 4.0.0 to 4.2.0, but the process keeps failing with:

Cookbook chef-client version 4.2.0 successfully installed
ERROR: IOError: Cannot open or read /home/jbibeau/chef-repo/cookbooks/chef-client/metadata.rb!

Looking at the fast forward merge that takes place, the metadata.rb file clearly gets deleted

Checking out the master branch.
Updating f3215c2..be2a18f
Fast-forward
...
 cookbooks/chef-client/metadata.rb                                                    | 35 -----------------------------------
...

I then tried to do a knife cookbook site download chef-client and looking at the raw .tar.gz, and it is indeed missing the metadata.rb file.

Is this a bug in the release? The file still seems to be present in the repo...
Thanks!

uninitialized constant WIN32OLE

In my base cookbook, I include these chef-client recipes in 'base::chef_client'

base::chef_client.rb

include_recipe 'chef-client::config'
include_recipe 'chef-client::default'
include_recipe 'chef-client::delete_validation'

In chef spec:

describe 'base::install on windows 2012' do
  let(:chef_run) do
    ChefSpec::Runner.new(
      platform: 'windows',
      version: '2012'
    ) do |node|
      node.set['base']['xxx'] = 'xxx'
    end.converge('base::install')
  end

  context 'when using install recipe' do
    it 'includes other recipe' do
      expect(chef_run).to include_recipe('base::chef_client')
    end
  end
end

Got this error with chefspec

 ================================================================================
Recipe Compile Error in /tmp/d20141030-8188-17chp5p/cookbooks/base/recipes/install.rb
================================================================================

NameError
---------
uninitialized constant WIN32OLE

Cookbook Trace:
---------------
  /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:42:in `wmi_property_from_query'
  /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:54:in `root_owner'
  /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:64:in `dir_owner'
  /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:90:in `create_directories'
  /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/recipes/config.rb:49:in `from_file'
  /tmp/d20141030-8188-17chp5p/cookbooks/base/recipes/chef_client.rb:3:in `from_file'
  /tmp/d20141030-8188-17chp5p/cookbooks/base/recipes/install.rb:13:in `from_file'

Relevant File Content:
----------------------
/tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:

 35:            Chef::Log.debug("Node has Chef Server Executable? #{system("which chef-server > /dev/null 2>&1")}") # ~FC048 Prefer Mixlib::ShellOut is ignored here
 36:            Chef::Log.debug("Node has Chef Server Ctl Executable? #{system("which chef-server-ctl > /dev/null 2>&1")}") # ~FC048 Prefer Mixlib::ShellOut is ignored here
 37:            node.recipe?('chef-server') || system('which chef-server > /dev/null 2>&1') || system('which chef-server-ctl > /dev/null 2>&1') # ~FC048 Prefer Mixlib::ShellOut is ignored here
 38:          end
 39:        end
 40:  
 41:        def wmi_property_from_query(wmi_property, wmi_query)
 42>>         @wmi = ::WIN32OLE.connect("winmgmts://")
 43:          result = @wmi.ExecQuery(wmi_query)
 44:          return nil unless result.each.count > 0
 45:          result.each.next.send(wmi_property)
 46:        end
 47:  
 48:        def chef_client_service_running
 49:          wmi_property_from_query(:name, "select * from Win32_Service where name = 'chef-client'") != nil
 50:        end
 51:  

F/tmp/d20141030-8188-17chp5p/cookbooks/omnibus_updater/libraries/omnitrucker.rb:3: warning: already initialized constant URL_MAP
[2014-10-30T11:50:59+01:00] WARN: Cloning resource attributes for service[chef-client] from prior resource (CHEF-3694)
[2014-10-30T11:50:59+01:00] WARN: Previous service[chef-client]: /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/recipes/init_service.rb:32:in `from_file'
[2014-10-30T11:50:59+01:00] WARN: Current  service[chef-client]: /tmp/d20141030-8188-17chp5p/cookbooks/omnibus_updater/recipes/installer.rb:9:in `from_file'
.

Failures:

  1) base::install on centos 6.5 when using install recipe includes other recipe
     Failure/Error: ChefSpec::Runner.new(
     TypeError:
       can't convert nil into String
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/recipes/delete_validation.rb:28:in `exists?'
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/recipes/delete_validation.rb:28:in `block (2 levels) in from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource/conditional.rb:86:in `call'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource/conditional.rb:86:in `evaluate_block'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource/conditional.rb:75:in `evaluate'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource/conditional.rb:66:in `continue?'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource.rb:713:in `block in should_skip?'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource.rb:712:in `each'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource.rb:712:in `find'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource.rb:712:in `should_skip?'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chefspec-4.0.2/lib/chefspec/extensions/chef/resource.rb:19:in `run_action'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/runner.rb:49:in `run_action'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/runner.rb:81:in `block (2 levels) in converge'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/runner.rb:81:in `each'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/runner.rb:81:in `block in converge'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection.rb:98:in `block in execute_each_resource'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/resource_collection.rb:96:in `execute_each_resource'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/runner.rb:80:in `converge'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/client.rb:345:in `converge'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chefspec-4.0.2/lib/chefspec/runner.rb:130:in `converge'
     # ./spec/unit/default/install_spec.rb:6:in `block (2 levels) in <top (required)>'
     # ./spec/unit/default/install_spec.rb:16:in `block (3 levels) in <top (required)>'

  2) base::install on windows 2012 when using install recipe includes other recipe
     Failure/Error: ChefSpec::Runner.new(
     NameError:
       uninitialized constant WIN32OLE
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:42:in `wmi_property_from_query'
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:54:in `root_owner'
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:64:in `dir_owner'
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/libraries/helpers.rb:90:in `create_directories'
     # /tmp/d20141030-8188-17chp5p/cookbooks/chef-client/recipes/config.rb:49:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `instance_eval'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/cookbook_version.rb:234:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:166:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:135:in `block in include_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:134:in `each'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:134:in `include_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
     # /tmp/d20141030-8188-17chp5p/cookbooks/base/recipes/chef_client.rb:3:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `instance_eval'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/cookbook_version.rb:234:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:166:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:135:in `block in include_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:134:in `each'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:134:in `include_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
     # /tmp/d20141030-8188-17chp5p/cookbooks/base/recipes/install.rb:13:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `instance_eval'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/mixin/from_file.rb:30:in `from_file'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/cookbook_version.rb:234:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:166:in `load_recipe'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context/cookbook_compiler.rb:140:in `block in compile_recipes'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context/cookbook_compiler.rb:138:in `each'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context/cookbook_compiler.rb:138:in `compile_recipes'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context/cookbook_compiler.rb:75:in `compile'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/run_context.rb:89:in `load'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chef-11.16.2/lib/chef/client.rb:265:in `setup_run_context'
     # /home/obazoud/.rvm/gems/ruby-1.9.3-p550/gems/chefspec-4.0.2/lib/chefspec/runner.rb:124:in `converge'
     # ./spec/unit/default/install_spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./spec/unit/default/install_spec.rb:35:in `block (3 levels) in <top (required)>'

See #176

Any tips ?

cron.daily errors on chef-client logrotate

On our systems (where we explicitly set the init_type to upstart, although perhaps on Ubuntu this might be the default) I am getting daily e-mail notifications from cron that it is unable to run /etc/init.d/chef-client. This is reasonable enough, since it does not exist (/etc/init/chef-client.conf has the upstart configuration instead). Changing the postrotate command to use initctl instead when the init_type is upstart (as I have done in PR#275) fixes this problem.

WARNING: Failed to connect to ip-

When I run the following command

knife ssh "role:servers" "touch /home/ubuntu/file.txt"

(output)
WARNING: Failed to connect to ip-172-31-30-34.us-west-2.compute.internal -- SocketError: getaddrinfo: nodename nor servname provided, or not known

WARNING: Failed to connect to ip-172-31-43-208.us-west-2.compute.internal -- SocketError: getaddrinfo: nodename nor servname provided, or not known

WARNING: Failed to connect to ip-172-31-36-181.us-west-2.compute.internal -- SocketError: getaddrinfo: nodename nor servname provided, or not known

WARNING: Failed to connect to ip-172-31-1-220.us-west-2.compute.internal -- SocketError: getaddrinfo: nodename nor servname provided, or not known

I believe the IP addresses for each server is not correct. The IP addresses where auto-detected when I first ran the chef-client. How can I run chef-client and have it detect the correct public IP?

Note, these servers are running on AWS EC2, this shouldn't make a difference but could provide some direction. Thanks :)

Test Kitchen Fails on RHEL Family with init init_style

Test Kitchen Fails To Provision On RHEL Family with the init (default) init_style. Below I'm using CentOS 6.5, but I've also seen failures on CentOS 6.4 and OL 6.5.

Interestingly, provisioning a node with knife bootstrap does not fail in these scenarios. Using runit seems to work still.

Chef Development Kit Version: 0.2.0
Test Kitchen version 1.2.2.dev 

log

           ================================================================================
           Error executing action `restart` on resource 'service[chef-client]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           Expected process to exit with [0], but received '6'
           ---- Begin output of /sbin/service chef-client restart ----
           STDOUT: Stopping chef-client: [FAILED]
           STDERR: 
           ---- End output of /sbin/service chef-client restart ----
           Ran /sbin/service chef-client restart returned 6


           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cookbooks/chef-client/recipes/init_service.rb

            32: service 'chef-client' do
            33:   supports :status => true, :restart => true
            34:   action [:enable, :start]
            35: end

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cookbooks/chef-client/recipes/init_service.rb:32:in `from_file'

           service("chef-client") do
             action [:enable, :start]
             updated true
             supports {:status=>true, :restart=>true}
             retries 0
             retry_delay 2
             guard_interpreter :default
             service_name "chef-client"
             enabled true
             pattern "chef-client"
             cookbook_name :"chef-client"
             recipe_name "init_service"
           end


       Running handlers:
       [2014-08-06T14:52:40+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2014-08-06T14:52:40+00:00] ERROR: Exception handlers complete
       [2014-08-06T14:52:40+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       Chef Client failed. 8 resources updated in 3.022506504 seconds
       [2014-08-06T14:52:40+00:00] ERROR: Chef::Exceptions::MultipleFailures
       [2014-08-06T14:52:40+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
>>>>>> Converge failed on instance <default-centos-65>.
>>>>>> Please see .kitchen/logs/default-centos-65.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: SSH exited (1) for command: [sudo -E chef-solo --config /tmp/kitchen/solo.rb --json-attributes /tmp/kitchen/dna.json  --log_level info]
>>>>>> ----------------------

kitchen.yml


---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: centos-6.5

suites:
  - name: default
    run_list:
      - recipe[chef-client]
    attributes:

Workaround, using runit:
default.rb

if platform_family?("rhel")
  include_recipe "runit::default"
  include_recipe "chef-client::runit_service"
  node.set[:chef_client][:init_style] = "runit"
end

Enhance Daemonized chef-client Shell Environment

While running under init, a daemonized chef-client doesn't provide the full environment offered by the user it's running as.

As a customer, I would appreciate a typical full shell login environment being made available to children of a daemonized chef-client running under init

The passenger_apache2 cookbook for example, depends on $HOME being present and fails otherwise.
sous-chefs/passenger_apache2#41

An example of a daemonized run outputting the available environment, then a run of the same recipe directly through sudo

Daemonized run output. $HOME is not present in the "I found something" output

[2014-12-04T00:34:13+00:00] INFO: Forking chef instance to converge...
[2014-12-04T00:34:13+00:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:


  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true


To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:


  knife ssl check -c /etc/chef/client.rb


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

[2014-12-04T00:34:13+00:00] INFO: *** Chef 11.16.4 ***
[2014-12-04T00:34:13+00:00] INFO: Chef-client pid: 9126
[2014-12-04T00:34:24+00:00] INFO: Run List is [recipe[chef-client::service], recipe[simplest]]
[2014-12-04T00:34:24+00:00] INFO: Run List expands to [chef-client::service, simplest]
[2014-12-04T00:34:24+00:00] INFO: Starting Chef Run for centos-6.2
[2014-12-04T00:34:24+00:00] INFO: Running start handlers
[2014-12-04T00:34:24+00:00] INFO: Start handlers complete.
[2014-12-04T00:34:35+00:00] INFO: Loading cookbooks [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]]
[2014-12-04T00:34:35+00:00] INFO: WindowsPackage lightweight resource already initialized -- overriding!
[2014-12-04T00:34:35+00:00] INFO: Processing directory[/var/run/chef] action create (chef-client::init_service line 97)
[2014-12-04T00:34:35+00:00] INFO: Processing directory[/var/cache/chef] action create (chef-client::init_service line 97)
[2014-12-04T00:34:35+00:00] INFO: Processing directory[/var/lib/chef] action create (chef-client::init_service line 97)
[2014-12-04T00:34:35+00:00] INFO: Processing directory[/var/log/chef] action create (chef-client::init_service line 97)
[2014-12-04T00:34:35+00:00] INFO: Processing directory[/etc/chef] action create (chef-client::init_service line 97)
[2014-12-04T00:34:35+00:00] INFO: Processing template[/etc/init.d/chef-client] action create (chef-client::init_service line 19)
[2014-12-04T00:34:35+00:00] INFO: Processing template[/etc/sysconfig/chef-client] action create (chef-client::init_service line 26)
[2014-12-04T00:34:35+00:00] INFO: Processing service[chef-client] action enable (chef-client::init_service line 32)
[2014-12-04T00:34:36+00:00] INFO: Processing service[chef-client] action start (chef-client::init_service line 32)
[2014-12-04T00:34:36+00:00] INFO: Processing log[I output a message] action write (simplest::default line 10)
[2014-12-04T00:34:36+00:00] INFO: I output a message
[2014-12-04T00:34:36+00:00] INFO: Processing log[I found something: TERM=xterm-256color
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin
PWD=/
LANG=en_US.UTF-8
SHLVL=2
_=/usr/bin/chef-client
] action write (simplest::default line 12)
[2014-12-04T00:34:36+00:00] INFO: I found something: TERM=xterm-256color
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin
PWD=/
LANG=en_US.UTF-8
SHLVL=2
_=/usr/bin/chef-client

[2014-12-04T00:34:41+00:00] INFO: Chef Run complete in 16.855542865 seconds
[2014-12-04T00:34:41+00:00] INFO: Running report handlers
[2014-12-04T00:34:41+00:00] INFO: Report handlers complete
[2014-12-04T00:34:41+00:00] INFO: Sending resource update report (run-id: 3029ba50-daee-428f-848b-9b84d328f749)

A direct run on the same box. $HOME is found in the "I found something" output

[vagrant@localhost ~]$ sudo chef-client
[2014-12-04T22:36:32+00:00] INFO: Forking chef instance to converge...
[2014-12-04T22:36:32+00:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:


  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true


To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:


  knife ssl check -c /etc/chef/client.rb


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Starting Chef Client, version 11.16.4
[2014-12-04T22:36:32+00:00] INFO: *** Chef 11.16.4 ***
[2014-12-04T22:36:32+00:00] INFO: Chef-client pid: 3754
[2014-12-04T22:36:44+00:00] INFO: Run List is [recipe[chef-client::service], recipe[simplest]]
[2014-12-04T22:36:44+00:00] INFO: Run List expands to [chef-client::service, simplest]
[2014-12-04T22:36:44+00:00] INFO: Starting Chef Run for centos-6.2
[2014-12-04T22:36:44+00:00] INFO: Running start handlers
[2014-12-04T22:36:44+00:00] INFO: Start handlers complete.
resolving cookbooks for run list: ["chef-client::service", "simplest"]
[2014-12-04T22:36:55+00:00] INFO: Loading cookbooks [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]]
Synchronizing Cookbooks:
  - chef-client
  - cron
  - chef_handler
  - logrotate
  - windows
[2014-12-04T22:37:00+00:00] INFO: Storing updated cookbooks/simplest/recipes/default.rb in the cache.
  - simplest
Compiling Cookbooks...
[2014-12-04T22:37:01+00:00] INFO: WindowsPackage lightweight resource already initialized -- overriding!
Converging 10 resources
Recipe: chef-client::init_service
  * directory[/var/run/chef] action create[2014-12-04T22:37:01+00:00] INFO: Processing directory[/var/run/chef] action create (chef-client::init_service line 97)
 (up to date)
  * directory[/var/cache/chef] action create[2014-12-04T22:37:01+00:00] INFO: Processing directory[/var/cache/chef] action create (chef-client::init_service line 97)
 (up to date)
  * directory[/var/lib/chef] action create[2014-12-04T22:37:01+00:00] INFO: Processing directory[/var/lib/chef] action create (chef-client::init_service line 97)
 (up to date)
  * directory[/var/log/chef] action create[2014-12-04T22:37:01+00:00] INFO: Processing directory[/var/log/chef] action create (chef-client::init_service line 97)
 (up to date)
  * directory[/etc/chef] action create[2014-12-04T22:37:01+00:00] INFO: Processing directory[/etc/chef] action create (chef-client::init_service line 97)
 (up to date)
  * template[/etc/init.d/chef-client] action create[2014-12-04T22:37:01+00:00] INFO: Processing template[/etc/init.d/chef-client] action create (chef-client::init_service line 19)
 (up to date)
  * template[/etc/sysconfig/chef-client] action create[2014-12-04T22:37:01+00:00] INFO: Processing template[/etc/sysconfig/chef-client] action create (chef-client::init_service line 26)
 (up to date)
  * service[chef-client] action enable[2014-12-04T22:37:01+00:00] INFO: Processing service[chef-client] action enable (chef-client::init_service line 32)
 (up to date)
  * service[chef-client] action start[2014-12-04T22:37:01+00:00] INFO: Processing service[chef-client] action start (chef-client::init_service line 32)
 (up to date)
Recipe: simplest::default
  * log[I output a message] action write[2014-12-04T22:37:01+00:00] INFO: Processing log[I output a message] action write (simplest::default line 10)
[2014-12-04T22:37:01+00:00] INFO: I output a message


  * log[I found something: HOSTNAME=localhost.localdomain
  TERM=xterm-256color
  HISTSIZE=1000
  LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lz=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.bz=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.rar=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
  MAIL=/var/spool/mail/vagrant
  LANG=en_US.UTF-8
  SHELL=/bin/bash
  LOGNAME=root
  USER=root
  USERNAME=root
  PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin
  HOME=/root
  SUDO_COMMAND=/usr/bin/chef-client
  SUDO_USER=vagrant
  SUDO_UID=500
  SUDO_GID=500
  ] action write[2014-12-04T22:37:01+00:00] INFO: Processing log[I found something: HOSTNAME=localhost.localdomain
TERM=xterm-256color
HISTSIZE=1000
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lz=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.bz=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.rar=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
MAIL=/var/spool/mail/vagrant
LANG=en_US.UTF-8
SHELL=/bin/bash
LOGNAME=root
USER=root
USERNAME=root
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin
HOME=/root
SUDO_COMMAND=/usr/bin/chef-client
SUDO_USER=vagrant
SUDO_UID=500
SUDO_GID=500
] action write (simplest::default line 12)
[2014-12-04T22:37:01+00:00] INFO: I found something: HOSTNAME=localhost.localdomain
TERM=xterm-256color
HISTSIZE=1000
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lz=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.bz=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.rar=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
MAIL=/var/spool/mail/vagrant
LANG=en_US.UTF-8
SHELL=/bin/bash
LOGNAME=root
USER=root
USERNAME=root
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/chef/embedded/bin:/opt/chef/embedded/bin:/usr/local/sbin:/usr/local/bin
HOME=/root
SUDO_COMMAND=/usr/bin/chef-client
SUDO_USER=vagrant
SUDO_UID=500
SUDO_GID=500



[2014-12-04T22:37:07+00:00] INFO: Chef Run complete in 22.738588401 seconds

Running handlers:
[2014-12-04T22:37:07+00:00] INFO: Running report handlers
Running handlers complete
[2014-12-04T22:37:07+00:00] INFO: Report handlers complete
Chef Client finished, 2/11 resources updated in 34.323542007 seconds
[2014-12-04T22:37:07+00:00] INFO: Sending resource update report (run-id: bbded1f6-5954-493d-98f8-3b502e207160)
[vagrant@localhost ~]$

Service Start is not working on FreeBSD

Chef client completes fine!

[....]

  • directory[/etc/rc.conf.d] action create (up to date)
    • template[/etc/rc.d/chef-client] action create (up to date)
    • template[/etc/rc.conf.d/chef] action create (up to date)
    • service[chef-client] action start (up to date)

However the service doesn't really start, tried several times to be sure, add to start it manually.

Also in freebsd it would be wise to use " /usr/local/etc/" and not "/etc"...

Cookbook failing under chef-client 12.1

With the latest chef-client release this cookbook is failing on CentOS and Amazon Linux (and possibly elsewhere?) due to an issue in the IIS cookbook. Easily replicated with a kitchen converge service-systemd-centos-70 Captured in sous-chefs/iis#149

Add user and password attribute on the recipe task for windows.

I installed the recipe task.rb from the cookbook chef-client for Windows and I noticed that the "run whether user is logged on or not" is not enabled, it seems when you want this option enabled in the windows_task resource you need add the user and password which this task will run, so is a good idea to add this option on the task.rb and also would be a good idea where you can get the password via data_bag.

chef-client cookbook does not reinstall service if definition has changed

We want to run the chef-client in a local user account instead of the system account. We can do this by wrapping the chef-client cookbook in our own cookbook and overwrite the attributes for username and password. However, chef does not correctly register that the service needs to be reinstalled if it has already been installed under the systems account.

chef-client removed by dist-upgrade

I have an Ubuntu 14.04 server on which chef-client was install by running knife bootstrap.

After running

sudo apt-get dist-upgrade

chef-client has been removed from the system.

The upgrade tries to update the chef-client from version 11.8.2-1 to 11.8.2-2. I get the following console output:

[[
The following packages will be upgraded:
chef
1 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/445 kB of archives.
After this operation, 107 MB disk space will be freed.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
(Reading database ... 118483 files and directories currently installed.)
Preparing to unpack .../archives/chef_11.8.2-2_all.deb ...
Unpacking chef (11.8.2-2) over (11.8.2-1.ubuntu.13.04) ...
dpkg: warning: unable to delete old directory '/opt/chef/embedded/bin': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby/gems/1.9.1/specifications': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby/gems/1.9.1/cache': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby/gems/1.9.1/gems': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby/gems/1.9.1': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby/gems': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib/ruby': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded/lib': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef/embedded': Directory not empty
dpkg: warning: unable to delete old directory '/opt/chef': Directory not empty
dpkg: warning: unable to delete old directory '/opt': Directory not empty
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up chef (11.8.2-2) ...

  • Starting chef-client chef-client Illegal option -d
    Illegal option -P
    /sbin/start-stop-daemon: unable to stat /var/run/chef/client.pid (No such file or directory)
    ]]

Chef-Client fails to start (init_service)

Running chef-client manually to get the chef-client auto-run config set on our nodes and it seems to not be able to start the chef-client service after the initial chef-run completes. Chef-client completes successfully, everything looks good...

ec2-xx-xx-xx-xx.compute-1.amazonaws.com * execute[update npm] action run
ec2-xx-xx-xx-xx.compute-1.amazonaws.com - execute npm update npm -g
ec2-xx-xx-xx-xx.compute-1.amazonaws.com Recipe: chef-client::init_service
ec2-xx-xx-xx-xx.compute-1.amazonaws.com * service[chef-client] action restart
ec2-xx-xx-xx-xx.compute-1.amazonaws.com - restart service service[chef-client]
ec2-xx-xx-xx-xx.compute-1.amazonaws.com Recipe: nginx::default
ec2-xx-xx-xx-xx.compute-1.amazonaws.com * service[nginx] action reload
ec2-xx-xx-xx-xx.compute-1.amazonaws.com - reload service service[nginx]
ec2-xx-xx-xx-xx.compute-1.amazonaws.com
ec2-xx-xx-xx-xx.compute-1.amazonaws.com Running handlers:
ec2-xx-xx-xx-xx.compute-1.amazonaws.com Running handlers complete
ec2-xx-xx-xx-xx.compute-1.amazonaws.com Chef Client finished, 33/272 resources updated in 162.122408732 seconds

... but when I check the service it doesn't show up as running.

ops@server:~$ ps aux | grep chef
ops 13137 0.0 0.0 8104 916 pts/1 S+ 22:06 0:00 grep chef

...also checking the status of the service returns an ok...

ops@one-desktop:~$ sudo /etc/init.d/chef-client status
* Checking status of chef-client chef-client [OK]

..checking the logs I see...

[2015-02-11T22:03:02+00:00] FATAL: Chef is already running pid 10237

That log is generated at around the same time as the chef-client run that I manually initiated to get chef-client cookbook on my node for the auto-run. If I manually start the service everything is good after that.

/etc/init.d/chef-client start
ops@server:~$ ps aux | grep chef
root 13217 0.0 1.0 134720 42180 ? Sl 22:17 0:00 /opt/chef/embedded/bin/ruby /usr/bin/chef-client -d -P /var/run/chef/client.pid -c /etc/chef/client.rb -i 300 -s 60
root 13248 50.9 2.1 718964 83504 ? Sl 22:18 0:15 chef-client worker: ppid=13217;start=22:18:19;

Logs start to generate as well, showing the chef-client is now running on the auto interval we set. I can do manually chef-runs after I start the service manually and it doesn't affect the daemon. Auto-runs will continue to run as normal.

Is there anything I can do to make sure the chef-client starts correctly after the first chef run to set it up? Wasn't sure if this was similar to this issue: #199

chef-client as upstart service does not reload correctly when upstart config has changed

The service is notified to restart when the upstart config has changed, which will be equivalent to service chef-client restart. This will restart the service but with the old configuration, http://upstart.ubuntu.com/cookbook/#restart.

This makes it tricky to change e.g. the interval config for the chef-client service. To make the service use the new upstart config it should be stopped and then started.

Will something like this work? Should it be :immediately?

notifies :stop, 'service[chef-client]', :delayed
notifies :start, 'service[chef-client]', :delayed

Typo in winsw_service.rb while including helpers.

In winsw_service recipe there is a typo that the include condition uses same class Recipe twice instead of using Resources.

class ::Chef::Recipe
include ::Opscode::ChefClient::Helpers
end
class ::Chef::Resource
include ::Opscode::ChefClient::Helpers
end

Major refactor of chef-client cookbook

I'd like to propose a complete refactoring of this cookbook. This constitutes a major version change and would likely break current use of the cookbook. As such it needs to be clearly communicated far and wide as to the intent, the rationale, and the scope. We need to make a version that works "as is" for the current state of the world and refer to that version for those who can't upgrade.

Background

This cookbook started life as the chef cookbook, and was intended to provide a way to set up a chef-client daemonized service and manage the /etc/chef/client.rb content, since chef was shipped as a RubyGem only, and RubyGems aren't packages that set up system services or manage their own configuration.

Over time this cookbook has grown in scope. It manages services across multiple different init systems and process supervisors. Some of those are hard dependencies that cause a dependency graph of epic proportions, or confusion (cron, logrotate, windows). Some of those are not hard dependencies, causing their use to not actually work if those cookbooks aren't included elsewhere on the node's run list (bluepill, daemontools, runit). There are more attributes than can be reasoned about in a rationale sense, causing cognitive load on new users.

Proposed Changes

I've broken up my thoughts on the changes I'm proposing into the following sections.

Services

Move all the service management recipes into per platform providers for a new chef_client_service resource for all the "native" services:

  • bsd
  • init
  • launchd
  • smf
  • src
  • upstart
  • systemd (does not exist, would be created)
  • windows

These would be per platform/platform family, and per platform version. As much as possible these should leverage core Chef resources to reduce additional dependencies.

Remove the "process supervision" style service management recipes out of this cookbook entirely. These could become new separate cookbooks with dependencies only on the supervision tool they use. For a proof of concept example of this, see chef-client-runit.

The service recipe could be rewritten to leverage the new chef_client_service resource so that the cookbook continues to work as is.

Example:

chef_client_service "upstart-example" do
  upstart_job_dir "/etc/init"
  action [:enable, :start]
end

Scheduler

Move the scheduled task / cron configuration to a new resource, chef_client_scheduler. This will set up chef-client to run on a schedule under "Scheduled Tasks" (Windows) or "cron" (Unix/Linux). This replaces the task and cron recipes.

However, it may worth considering that running chef-client going forward should not be as a cron job or scheduled task. The reason for that in the past was because the process would grow over time when run as a resident service, but the default mode of running is to fork a worker process as of Chef 11.6 (released July 23, 2013).

Configuration

Management of /etc/chef/client.rb will be moved to a new resource, chef_client_config. Attributes can be preserved and be passed into the resource. Additional configuration concerns need to be handled:

  • Log rotation (see next section)
  • Report/exception handlers
  • Ohai plugin management
  • Gems required by Chef for configuration purposes
  • "Dot d" directory inclusion

Examples:

chef_client_config "/etc/chef/client.rb" do
  options node['chef_client']['config']
end

chef_client_config "/etc/chef/client.d/my_config.rb" do
  options(:option_key => "option-value", :its => "a hash")
end

Logging

Log rotation/log management may fall under configuration.

We should have a sane way to get Syslog (Unix/Linux) and Event Viewer (Windows) logging in place through configuration. Even if that is just an example that we can document in the README.md, that's okay).

Some "Rules"

Some rules I'd like to follow with this refactoring, and this is incomplete, and up for embellishment/bikeshedding.

No attribute settings in recipes. All attributes will be set in attributes/default.rb to sane and sensible defaults.

No per-platform attributes except if they should be user-tunable. These should be in the per-platform providers for the relevant resources.

We will not support for Chef 10. We'll make a decent effort to support Chef 11, but we're targeting Chef 12 and may make use of Chef 12 features/changes (such as those to chef_gem in 12.1.0). We'll have an older major version updated to work with Chef 11 and ongoing support will be on a best effort basis.

We must have 100% test coverage between ChefSpec unit tests, and ServerSpec integration/post convergence tests.

As much as reasonably possible, we should support running an instance of chef-client as non-privileged.

We should play nice with Chef Server, in that users may wish to manage their Chef Server with chef-client (insert yo dawg joke).

The resources implemented in this cookbook will be in libraries and subclass the Chef::Resource::LWRPBase and Chef::Provider::LWRPBase. We'll also need to write corresponding matchers for others to use ChefSpec, in libraries/matchers.rb.

Certain attributes may be replaced with helper methods. Those will be written in libraries/helpers.rb. If namespacing is deemed a requirement for helpr methods, I propose ChefClientCookbook as the module name.

All outstanding issues and pull requests need to be addressed. See comment below.

UTF-8 Encoding and Ruby - ERROR: "\xC3" on US-ASCII

We have noticed in our /var/log/chef/client.log the following error.

[2014-10-30T17:28:56+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-10-30T17:28:56+00:00] ERROR: "\xC3" on US-ASCII

When we run chef-client in the foreground, we have no issues.

We are running Ubuntu 14.04 LTS and ruby 1.9.3

chef_server_url cannot be set through the attributes

No matter what I declare in the attributes I always get

chef_server_url "https://localhost:443"
in the client.rb file.

My attributes for Chef-Solo

{
  "chef-client": {
    "config": {
      "chef_server_url": "https://XXX.YYY.ZZZ.AAA:443",
      "validation_client_name" : "chef-validator"
    }
  },
"run_list": [
    "chef-client::config",
    "chef-client::service"
  ]
}

The command I run:
sudo chef-solo -c solo.rb -j node.json

The content of client.rb

chef_server_url "https://localhost:443"
validation_client_name "chef-validator"
# Using default node name (fqdn)


Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"

Dir.glob(File.join("/etc/chef", "client.d", "*.rb")).each do |conf|
  Chef::Config.from_file(conf)
end

The OS is Amazon Linux.

Kind regards.

RHEL 7 check breaks Amazon systems

Fails because it tries to add a file to /etc/systemd on an Amazon image as per

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/chef-client/recipes/systemd_service.rb

 16: template "/etc/systemd/system/chef-client.service" do
 17:   source "#{dist_dir}/systemd/chef-client.service.erb"
 18:   mode 0644
 19:   variables(:client_bin => client_bin, :sysconfig_file => "/etc/#{conf_dir}/chef-client")
 20:   notifies :restart, "service[chef-client]", :delayed
 21: end
 22:

Platform version details for the Amazon image is something like

"platform": "amazon",
"platform_version": "2014.09",
"platform_family": "rhel",

So when the attribute checks the platform family and version, it sees that "2014.09" is greater than 7 so sets the init style to systemd:

when 'rhel'
  if node['platform_version'].to_i >= 7
    default['chef_client']['init_style'] = 'systemd'
  else
    default['chef_client']['init_style'] = 'init'
  end

log files not in human readable format

So it looks like the -tt flag is in the runit log script, but my log files look like this:

/var/log/chef# ls
@4000000053f132b438d022d4.s  @4000000053f1a249319e916c.s  @4000000053f214ef1cd2e9f4.s  @4000000053f284622cfd3064.s
@4000000053f1584c1d9a4134.s  @4000000053f1c8bf365aa664.s  @4000000053f239400702d29c.s  current
@4000000053f17de91c92b08c.s  @4000000053f1ef703365bcdc.s  @4000000053f25ed80bb0a33c.s  lock

any idea why this might be?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.