Giter VIP home page Giter VIP logo

homebrew's Introduction

Homebrew Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

This cookbook installs Homebrew and provides resources for working with taps and casks

Note: The homebrew_tap and homebrew_cask resources shipped in Chef 14.0. When Chef 15.0 is released in April 2019 these resources will be removed from this cookbook as all users should be on 14.0 or later.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

  • macOS

Chef

  • Chef 12.7+

Cookbooks

  • none

Resources

homebrew_tap

Resource for brew tap, a Homebrew command used to add additional formula repositories. From the brew man page:

brew tap [--full] user/repo [URL]
    Tap a formula repository.

    With URL unspecified, taps a formula repository from GitHub using HTTPS.
    Since so many taps are hosted on GitHub, this command is a shortcut for
    tap user/repo https://github.com/user/homebrew-repo.

    With URL specified, taps a formula repository from anywhere, using
    any transport protocol that git handles. The one-argument form of tap
    simplifies but also limits. This two-argument command makes no
    assumptions, so taps can be cloned from places other than GitHub and
    using protocols other than HTTPS, e.g., SSH, GIT, HTTP, FTP(S), RSYNC.

    By default, the repository is cloned as a shallow copy (--depth=1), but
    if --full is passed, a full clone will be used. To convert a shallow copy
    to a full copy, you can retap passing --full without first untapping.

Default action is :tap which enables the repository. Use :untap to disable a tapped repository.

Actions

  • :tap (default) - Add a tap
  • :untap - Remove a tap

Properties

  • :tap_name - Optional name property to override the resource name value
  • :url - Optional URL to the tap
  • :full - Perform a full clone rather than a shallow clone on the tap (default: false)
  • :homebrew_path - the path to the homebrew binary (default: '/opt/homebrew/bin/brew')
  • :owner - the owner of the homebrew installation (default: calculated based on existing files)

Examples

homebrew_tap 'homebrew/dupes'

homebrew_tap 'homebrew/dupes' do
  action :untap
end

homebrew_tap "Let's install homebrew/dupes" do
  tap_name 'homebrew/dupes'
  url 'https://github.com/homebrew/homebrew-dupes.git'
  full true
end

homebrew_cask

Resource for brew cask, a Homebrew-style CLI workflow for the administration of Mac applications distributed as binaries. It's implemented as a homebrew "external command" called cask.

homebrew-cask on GitHub

Actions

  • :install (default) - install an Application
  • :remove - remove an Application.

Properties

  • :cask_name - Optional name property to override the resource name value
  • :options - options to pass to the brew CLI during installation
  • :install_cask - auto install cask tap if necessary (default: true)
  • :homebrew_path - the path to the homebrew binary (default: '/opt/homebrew/bin/brew')
  • :owner - the owner of the homebrew installation (default: calculated based on existing files)

Examples

homebrew_cask 'google-chrome'

homebrew_cask "Let's remove google-chrome" do
  cask_name 'google-chrome'
  install_cask false
  action :remove
end

View the list of available Casks

Attributes

  • node['homebrew']['owner'] - The user that will own the Homebrew installation and packages. Setting this will override the default behavior which is to use the non-privileged user that has invoked the Chef run (or the SUDO_USER if invoked with sudo). The default is nil.

  • node['homebrew']['auto-update'] - Whether the default recipe should automatically update Homebrew each run or not. The default is true to maintain compatibility. Set to false or nil to disable. Note that disabling this feature may cause formula to not work.

  • node['homebrew']['formulas'] - An Array of formula that should be installed using Homebrew by default, used only in the homebrew::install_formulas recipe.

    • To install the most recent version, include just the recipe name: - simple_formula

    • To install a specific version, specify both its name and version:

      - name: special-version-formula
        version: 1.2.3
    • To install the HEAD of a formula, specify both its name and head: true:

      - name: head-tracking-formula
        head: true
    • To provide other options, specify both its name and options

      - name: formula-with-options
        options: --with-option-1 --with-other-option
  • node['homebrew']['casks'] - An Array of casks that should be installed using brew cask by default, used only in the homebrew::install_casks recipe.

  • node['homebrew']['taps'] - An Array of taps that should be installed using brew tap by default, used only in the homebrew::install_taps recipe. For example:

    [
      'homebrew/science',
      # 'tap' is the only required key for the Hash
      { 'tap' => 'homebrew/dupes', 'url' => 'https://github.com', 'full' => true }
    ]

Usage

We strongly recommend that you put "recipe[homebrew]" in your node's run list, to ensure that it is available on the system and that Homebrew itself gets installed. Putting an explicit dependency in the metadata will cause the cookbook to be downloaded and the library loaded, thus resulting in changing the package provider on macOS, so if you have systems you want to use the default (Mac Ports), they would be changed to Homebrew.

The default recipe also ensures that Homebrew is installed and up to date if the auto-update attribute (above) is true (default).

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website

homebrew's People

Contributors

amarshall avatar antonofthewoods avatar bdwyertech avatar brantone avatar coderanger avatar cwebberops avatar damacus avatar fnichol avatar jeremyolliver avatar jeroenj avatar josegonzalez avatar jrwesolo avatar jtimberman avatar kitchen-porter avatar mathie avatar onewland avatar ramereth avatar renovate[bot] avatar schisamo avatar seanfisk avatar sergiopatino avatar sethvargo avatar shouser avatar spesnova avatar stevemarshall avatar stissot avatar tas50 avatar wendorf avatar williamtheaker 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  avatar  avatar  avatar  avatar  avatar

homebrew's Issues

Homebrew need sudoers right without password when using chef as service

Cookbook version

2.1.0

Chef-client version

12.12.15

Platform Details

OS X 10.11.6 with chef-client run as service (created by chef-client resource)

Scenario:

When deploying system, a kickstart script install chef and register workstation to my chef server and run content from a default role.

No one is connected and the workstation is made for multiple non admin user.

A default admin user is installed and set as target user for homebrew via node attributes.

Expected Result:

Homebrew should be able installed and scenario should continue.

Actual Result:

Homebrew install fail due to design errors in the way homebrew work (it's not your fault, homebrew is a PITA in term of system management, nothing is done properly).

Here is the error:

Expected process to exit with [0], but received '1'
---- Begin output of /var/chef/cache/homebrew_go ----
STDOUT: ==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
==> /usr/bin/sudo /bin/mkdir -p /Users/macadmin/Library/Caches/Homebrew
STDERR: sudo: no tty present and no askpass program specified
Failed during: /usr/bin/sudo /bin/mkdir -p /Users/macadmin/Library/Caches/Homebrew
---- End output of /var/chef/cache/homebrew_go ----
Ran /var/chef/cache/homebrew_go returned 1

Indeed, homebrew install script make a heavy use of sudo command. But they never thinked about mass deployment scenario where sudo isn't available…

To make this work you've to add a file with the following content to /etc/sudoers.d

<homebrew owner>        ALL=(ALL) NOPASSWD: ALL

And then, it work…

It might be interesting to package this hack into the homebrew installer recipe…

(of course, create this file only if needed and delete it as soon as possible)

Casks being partially matched

Casks are being partially matched, causing casks with a longer, similar name to not be installed, eg. cask vagrant won't be installed if cask vagrant-manager is installed. #83 should fix it.

"brew cask list" no longer supported

https://github.com/chef-cookbooks/homebrew/blob/master/resources/cask.rb#L63

/usr/local/bin/brew cask list
Error: Calling brew cask list is disabled! Use brew list [--cask] instead.

brew list --cask or brew list --cask $name works as expected

  * homebrew_cask[phantomjs] action install
    * homebrew_tap[homebrew/cask] action tap (up to date)

    ================================================================================
    Error executing action `install` on resource 'homebrew_cask[phantomjs]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of /usr/local/bin/brew cask list 2>/dev/null ----
    STDOUT:
    STDERR:
    ---- End output of /usr/local/bin/brew cask list 2>/dev/null ----
    Ran /usr/local/bin/brew cask list 2>/dev/null returned 1

    Resource Declaration:
    ---------------------
    # In /var/folders/cl/02xl4t9d747bw65yqssyl0_40000gp/T/cookbooks.0mnh7hCZ/site-cookbooks/workstation-wrapper/recipes/default.rb

     22: homebrew_cask 'phantomjs' do
     23:   options '--appdir=/Applications'
     24: end
     25:

    Compiled Resource:
    ------------------
    # Declared in /var/folders/cl/02xl4t9d747bw65yqssyl0_40000gp/T/cookbooks.0mnh7hCZ/site-cookbooks/workstation-wrapper/recipes/default.rb:22:in `from_file'

    homebrew_cask("phantomjs") do
      action [:install]
      default_guard_interpreter :default
      declared_type :homebrew_cask
      cookbook_name :"workstation-wrapper"
      recipe_name "authpoxy"
      options "--appdir=/Applications"
      cask_name "phantomjs"
      homebrew_owner_uid 502
      homebrew_owner_username "user"
      owner "user"
    end

    System Info:
    ------------
    chef_version=16.8.14
    platform=mac_os_x
    platform_version=10.15.7
    ruby=ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
    program_name=/opt/cinc-workstation/bin/cinc-solo
    executable=/opt/cinc-workstation/bin/cinc-solo


Running handlers:
[2020-12-21T18:08:41-05:00] ERROR: Running exception handlers
Running handlers complete
[2020-12-21T18:08:41-05:00] ERROR: Exception handlers complete
Cinc Client failed. 30 resources updated in 02 minutes 09 seconds
[2020-12-21T18:08:41-05:00] FATAL: Stacktrace dumped to /var/chef/cache/cinc-stacktrace.out
[2020-12-21T18:08:41-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2020-12-21T18:08:41-05:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: homebrew_cask[phantomjs] (workstation-wrapper::default line 22) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /usr/local/bin/brew cask list 2>/dev/null ----
STDOUT:
STDERR:
---- End output of /usr/local/bin/brew cask list 2>/dev/null ----
Ran /usr/local/bin/brew cask list 2>/dev/null returned 1

HOMEBREW_CACHE replacement during installation?

Cookbook version

2.1.0

Chef-client version

12.12.15

Platform Details

OS X 10.11.6 with chef-client run as service (created by chef-client resource)

Scenario:

When deploying system, a kickstart script install chef and register workstation to my chef server and run content from a default role.

The kickstart occur when the target admin account owning the homebrew setup has never been logged to the Mac (installation done with https://github.com/MagerValp/CreateUserPkg)

Steps to Reproduce:

Run the homebrew installation from chef-client run as a launchd service when the target admin as never been connected to the mac

Expected Result:

homebrew should install and admin account should be OK

Actual Result:

Due to HOMEBREW_CACHE localization, the installer create a partial home folder for the never logged admin.

When the admin authenticate after, the system will display a lot of errors saying that Library is broken. This is because home folder exist but is empty. So all OS X home folder creation system are blocked due to files in HOMEBREW_CACHE

Homebrew cookbook should play with env to avoid using cache folder in /Users but in /tmp for example.

Installing android-studio-canary

Cookbook version

4.1.0

Chef-client version

12.17.44

Platform Details

MacOS Sierra 10.12.5

Scenario:

Using chef-cookbooks/homebrew to install caskroom/versions/android-studio-canary

Steps to Reproduce:

Add

homebrew_cask "android-studio" 
homebrew_cask "android-studio-canary" 

To your recipe

Expected Result:

I want android-studio and android-studio-canary to be installed

Actual Result:

chef-cookbooks/homebrew can't find "android-studio-canary" cask, only android-studio is installed

On the command line i can execute both:

  brew cask install caskroom/versions/android-studio-canary
  brew install caskroom/versions/android-studio-canary

And android-studio-canary is installed successfully

homebrew_package fails too early if homebrew is installed but homebrew_user has been removed

There is a bit of a chicken and egg problem here, that should fail more gracefully.

A run-list that creates an OS X user, and then installs homebrew for that user, works as expected.

However, if you later remove the user (like during testing), everything breaks badly (unless you also uninstall homebrew), even though the user would be re-created before it is actually needed by homebrew or any package installs.

This seems to happen because a cookbook library detects that homebrew is installed and has a homebrew_owner defined, and then can't find that user, and fails. It might be better, if this only generated a warning and continued. That way if this user is recreated before the first package call, things should still work fine.

If you get to the first package and the user still doesn't exist, this seems like a better time to have a fatal error.

Ruby Homebrew installer is now deprecated and should be migrated to Bash

Cookbook version

5.0.8

Chef-client version

15.8.23

Platform Details

mac_os_x

Scenario:

Error executing action run on resource 'execute[install homebrew]'

STDERR: Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in
           Bash. Please migrate to the following command:
             /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

uninitialized constant Chef::Resource::HomebrewTap Chef 13.0.118

Cookbook version

3.0.0

Chef-client version

13.0.118

Platform Details

mac_os_x 10.12.2 (Sierra)

Scenario:

install java using java cookbook, but homebrew recipe fails even before that.

Steps to Reproduce:

include_recipe 'java::default'

source: java cookbook: homebrew recipe

include_recipe 'homebrew'
include_recipe 'homebrew::cask'
include_recipe 'java::notify'

homebrew_tap 'caskroom/versions'
homebrew_cask "java#{node['java']['jdk_version']}" do
  notifies :write, 'log[jdk-version-changed]', :immediately
end

Expected Result:

java installed

Actual Result:

Error executing action tap on resource 'homebrew_tap[caskroom/cask]'


Recipe: homebrew::cask
         * homebrew_tap[caskroom/cask] action tap[2017-04-18T08:36:24+00:00] INFO: Processing homebrew_tap[caskroom/cask] action tap (homebrew::cask line 20)
       [2017-04-18T08:36:24+00:00] INFO: Processing homebrew_tap[caskroom/cask] action tap (homebrew::cask line 20)
       
           
           ================================================================================
           Error executing action `tap` on resource 'homebrew_tap[caskroom/cask]'
           ================================================================================
           
           NameError
           ---------
           uninitialized constant Chef::Resource::HomebrewTap
           
           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/homebrew/providers/tap.rb:27:in `load_current_resource'
           
           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/homebrew/recipes/cask.rb
           
            20: homebrew_tap 'caskroom/cask'
            21: 
           
           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/homebrew/recipes/cask.rb:20:in `from_file'
           
           homebrew_tap("caskroom/cask") do
             action [:tap]
             default_guard_interpreter :default
             declared_type :homebrew_tap
             cookbook_name "homebrew"
             recipe_name "cask"
           end
           
           System Info:
           ------------
           chef_version=13.0.118
           platform=mac_os_x
           platform_version=10.12.2
           ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin14]
           program_name=chef-client worker: ppid=920;start=08:31:53;
           executable=/opt/chef/bin/chef-client
           


Homebrew Installation - ENV['USER']

Proper Homebrew installation is highly dependent upon ENV['USER'] being set properly.
https://github.com/Homebrew/install/blob/7a8c21862ec3cdb3858037f5edc7bc8958bec23e/install#L123

From experience, I can say that execute resources often do not populate the typical environmental variables properly.
http://tickets.opscode.com/browse/CHEF-2288

Homebrew and Casks (at least when installed via Vagrant Chef run) are not picking up the homebrew_user's environment properly, causing folder ownership to be set incorrectly. (e.g. /usr/local/bin, /Library/Caches/Homebrew/Cask)

The user in question should be vagrant, not root. Root is derived from ENV['USER'] in this case, even though homebrew_user is properly grabbing vagrant. There is a check in the homebrew_mixin library that would have coughed if homebrew_user was actually root.

==> default: /usr/local/Library/...
==> default:               /usr/local/share/man/man1/brew.1
==> default:               ==> The following directories will be made group writable:
==> default:               /usr/local/bin
==> default:               ==> The following directories will have their owner set to root:
==> default:               /usr/local/bin
==> default:               ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin
==> default:               ==> /usr/bin/sudo /usr/sbin/chown root /usr/local/bin
==> default:               ==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> default:               ==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> default:               ==> /usr/bin/sudo /usr/sbin/chown root /Library/Caches/Homebrew

I will make a PR soon to fix this, adding environment into the execute resources like below. This should make this cookbook idempotent from a shell perspective (i.e. Vagrant, VirtualBox/VMware & OS X, where I test my developer environment)

execute 'install homebrew' do
  command homebrew_go
  environment lazy { ({ 'HOME' => ::Dir.home(homebrew_owner), 'USER' => homebrew_owner }) }
  user homebrew_owner
  not_if { ::File.exist? '/usr/local/bin/brew' }
end

fix broken specs on master

Failures:

  1) homebrew::cask non-default, specified by attribute user updates homebrew cask as alaska
     Failure/Error: expect(chef_run).to run_execute('update homebrew cask from github').with(
       expected "execute[update homebrew cask from github]" to have parameters:

         user "alaska", was 501
     # ./spec/recipes/cask_spec.rb:42:in `block (3 levels) in <top (required)>'

  2) homebrew::default non-default, specified by attribute user installs homebrew as the alaska user
     Failure/Error: expect(chef_run).to run_execute('install homebrew').with(
       expected "execute[install homebrew]" to have parameters:

         user "alaska", was 501
     # ./spec/recipes/default_spec.rb:57:in `block (3 levels) in <top (required)>'

brew install after @881fdcd hangs on

Cookbook version

[Version of the cookbook where you are encountering the issue]

Chef-client version

[Version of chef-client in your environment]

Platform Details

[Operating system distribution and release version. Cloud provider if running in the cloud]

Scenario:

[What you are trying to achieve and you can't?]

Steps to Reproduce:

[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?]

Expected Result:

[What are you expecting to happen as the consequence of above reproduction steps?]

Actual Result:

[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]

add options to homebrew_cask

I used to work around this by doing something like:

homebrew_cask 'iterm2 --appdir=/Applications'

except now it seems this is prevented by regex validation:

chef 12.1.0:

Chef::Exceptions::ValidationFailed
---------------------------------
Option name's value iterm2 --appdir=/Applications does not match regular expression /^[\w-]+$/

Ideally the LWRP should support option passing

homebrew_cask 'iterm2' do
options '--appdir=/Applications'
end

TypeError: no implicit conversion of Fixnum into String

Homebrew for Chef 12.3.0 on Mac OS X 10.10.3 throws TypeError: no implicit conversion of Fixnum into String. But homebrew works for Chef 12.0.3.

Stacktrace:

     Starting Chef Client, version 12.3.0
       Compiling Cookbooks...
       Recipe: chrome::dmg
        (up to date)
         Converging 14 resources
       Recipe: homebrew::default
        (up to date)
         * execute[install homebrew] action run (skipped due to not_if)
        (skipped due to not_if)

           - execute /usr/local/bin/brew update || true
       Recipe: homebrew::cask
         * homebrew_tap[caskroom/cask] action tap (up to date)


           ================================================================================
           Error executing action `install` on resource 'homebrew_package[brew-cask]'
           ================================================================================

           TypeError
           ---------
           no implicit conversion of Fixnum into String

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cookbooks/homebrew/libraries/homebrew_package.rb:102:in `getpwnam'
           /tmp/kitchen/cookbooks/homebrew/libraries/homebrew_package.rb:102:in `get_response_from_command'
           /tmp/kitchen/cookbooks/homebrew/libraries/homebrew_package.rb:70:in `brew'
           /tmp/kitchen/cookbooks/homebrew/libraries/homebrew_package.rb:50:in `install_package'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cookbooks/homebrew/recipes/cask.rb

            23: package 'brew-cask'
            24:

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cookbooks/homebrew/recipes/cask.rb:23:in `from_file'

           homebrew_package("brew-cask") do
             action :install
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             package_name "brew-cask"
             version "0.54.0"
             timeout 900
             declared_type :package
             cookbook_name :homebrew
             recipe_name "cask"
           end


       Running handlers:
       [2015-05-20T22:07:24-07:00] ERROR: Running exception handlers
       Running handlers complete
       [2015-05-20T22:07:24-07:00] ERROR: Exception handlers complete
       [2015-05-20T22:07:24-07:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       Chef Client failed. 1 resources updated in 12.885101 seconds
       [2015-05-20T22:07:24-07:00] ERROR: homebrew_package[brew-cask] (homebrew::cask line 23) had an error: TypeError: no implicit conversion of Fixnum into String
       [2015-05-20T22:07:24-07:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Analytics shell_out breaks chefspec

When the homebrewrecipe is included and the chefspec tests are running on a non-homebrew box (or Linux), the following error is thrown:

1) base::osx executes the homebrew cookbook
   Failure/Error: cached(:chef_run) { ChefSpec::ServerRunner.new(platform: 'mac_os_x', version: '10.12').converge(described_recipe) }
   
   Errno::ENOENT:
     No such file or directory - /usr/local/bin/brew
   # /var/folders/48/v3jpvqg155d2qfktth99_8t40000gp/T/chefspec20161223-30733-n42dowfile_cache_path/cookbooks/homebrew/recipes/default.rb:44:in `block (2 levels) in from_file'
   # ./spec/recipes/osx_spec.rb:4:in `block (2 levels) in <top (required)>'
   # ./spec/recipes/osx_spec.rb:19:in `block (2 levels) in <top (required)

osx.rb recipe code:

include_recipe 'build-essential'
include_recipe 'homebrew'

chefspec code:

describe 'base::osx' do
  cached(:chef_run) { ChefSpec::ServerRunner.new(platform: 'mac_os_x', version: '10.12').converge(described_recipe) }

  before do
    stub_command('which git').and_return(true)
  end

  it 'executes the homebrew cookbook' do
    expect(chef_run).to include_recipe('homebrew')
  end
end

AFAIK this is caused by the latest "disable analytics" feature and its shell_out call, see 23257de

While I am aware of shell_out stubbing in chefspec (chefspec/chefspec#264) I hate it because I always need to know what a cookbook internally does when I just want to check the include_recipe call.

get_version_from_formula: Couldn't find HOME environment

I run Chef on Mac OS X via Launchd in interval mode instead of as a daemon. The homebrew::cask recipe is part of my run list, but I get the following error:

[2014-08-18T18:18:08+02:00] INFO: Processing package[brew-cask] action install (homebrew::cask line 22)
ESC[0m
================================================================================ESC[0m
ESC[31mError executing action `install` on resource 'package[brew-cask]'ESC[0m
================================================================================ESC[0m

ESC[0mArgumentErrorESC[0m
-------------ESC[0m
couldn't find HOME environment -- expanding `~'ESC[0m

ESC[0mCookbook Trace:ESC[0m
---------------ESC[0m
/var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:89:in `get_version_from_formula'
ESC[0m/var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:69:in `current_installed_version'
ESC[0m/var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:39:in `load_current_resource'ESC[0m

ESC[0mResource Declaration:ESC[0m
---------------------ESC[0m
# In /var/chef/cache/cookbooks/homebrew/recipes/cask.rb
ESC[0m
ESC[0m 22: package 'brew-cask'
ESC[0m
ESC[0mCompiled Resource:ESC[0m
------------------ESC[0m
# Declared in /var/chef/cache/cookbooks/homebrew/recipes/cask.rb:22:in `from_file'
ESC[0m
ESC[0mpackage("brew-cask") do
ESC[0m  action :install
ESC[0m  retries 0
ESC[0m  retry_delay 2
ESC[0m  guard_interpreter :default
ESC[0m  package_name "brew-cask"
ESC[0m  timeout 900
ESC[0m  cookbook_name "homebrew"
ESC[0m  recipe_name "cask"
ESC[0mend
ESC[0m
ESC[0m[2014-08-18T18:18:08+02:00] INFO: Running queued delayed notifications before re-raising exception
[2014-08-18T18:18:08+02:00] ERROR: Running exception handlers
[2014-08-18T18:18:08+02:00] ERROR: Exception handlers complete
[2014-08-18T18:18:08+02:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-08-18T18:18:08+02:00] INFO: Sending resource update report (run-id: d837723e-bb95-4c9f-ba59-a77aa1a36a8a)
[2014-08-18T18:18:09+02:00] ERROR: package[brew-cask] (homebrew::cask line 22) had an error: ArgumentError: couldn't find HOME environment -- expanding `~'

In get_response_from_command, the HOME variable is explicitly retrieved. Shouldn't the same be done in get_response_from_formula ??

Support arm64 install of Homebrew

🗣️ Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

👻 Brief Description

Despite installing Homebrew (via their recommended Bash command), the cookbook is attempting to re-install (and in some cases can throw an error).

🥞 Cookbook version

5.2.2

👩‍🍳 Chef-Infra Version

13 -> 17

🎩 Platform details

macOS 11.0.1 - arm64

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install Homebrew
  2. Run sudo chef-client
  3. Error: Need sudo access on macOS

🚓 Expected behavior

Not attempt to re-install Homebrew

➕ Additional context

The check here https://github.com/sous-chefs/homebrew/blob/main/libraries/helpers.rb#L32 looks for /usr/local/bin/brew.
But for arm64, installs into /opt/homebrew : https://github.com/Homebrew/install/blob/master/install.sh#L35

Possible solution:

  • looks for file in either location
  • manually install Homebrew with arch -x86_64

Cookbook-provided package provider still used on Chef 12

Cookbook version

2.1.2

Chef-client version

12.17.44

Platform Details

macOS 10.12.2 (x86_64-darwin13)

Scenario:

Marking a package with action :upgrade fails when the package is not installed, which, per #58 is intentionally left broken on Chef <12, but should work on Chef 12.

Steps to Reproduce:

Mark a package that has never been installed with action :upgrade. Why precisely the cookbook-provided package provider is used on Chef 12 is unknown. Note that, while the “git” package is used here, substituting an alternative package yields the same failure.

Expected Result:

Successfully installs package, seemingly using the built-in (non-cookbook) package provider.

Actual Result:

-----> Starting Kitchen (v1.14.2)
-----> Converging <>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 5.3.0...
       Removing non-cookbook files before transfer
       Preparing roles
       Preparing solo.rb
-----> Chef Omnibus installation detected (install only if missing)
       Transferring files to <>
       Starting Chef Client, version 12.17.44
       resolving cookbooks for run list: ["homebrew", "workstation::git"]
       Synchronizing Cookbooks:
         - homebrew (2.1.2)
         - build-essential (7.0.2)
         - workstation (0.0.0)
         - mingw (1.2.4)
         - seven_zip (2.0.2)
         - compat_resource (12.16.2)
         - windows (2.1.1)
         - ohai (4.2.3)
       Installing Cookbook Gems:
       Compiling Cookbooks...
       Converging 5 resources
       Recipe: homebrew::default
         * remote_file[/tmp/kitchen/cache/homebrew_go] action create (up to date)
         * execute[install homebrew] action run (skipped due to not_if)
         * homebrew_package[git] action install (skipped due to not_if)
         * execute[update homebrew from github] action run
           - execute /usr/local/bin/brew update || true
       Recipe: workstation::git
         * homebrew_package[git] action upgrade

           ================================================================================
           Error executing action `upgrade` on resource 'homebrew_package[git]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           Expected process to exit with [0], but received '1'
           ---- Begin output of brew upgrade git ----
           STDOUT:
           STDERR: Error: git not installed
           ---- End output of brew upgrade git ----
           Ran brew upgrade git returned 1

           Cookbook Trace:
           ---------------
           /tmp/kitchen/cache/cookbooks/homebrew/libraries/homebrew_package.rb:95:in `get_response_from_command'
           /tmp/kitchen/cache/cookbooks/homebrew/libraries/homebrew_package.rb:70:in `brew'
           /tmp/kitchen/cache/cookbooks/homebrew/libraries/homebrew_package.rb:54:in `upgrade_package'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/workstation/recipes/git.rb

             1: package 'git' do
             2:   action :upgrade
             3: end

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/workstation/recipes/git.rb:1:in `from_file'

           homebrew_package("git") do
             package_name "git"
             action [:upgrade]
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             declared_type :package
             cookbook_name "workstation"
             recipe_name "git"
           end

           Platform:
           ---------
           x86_64-darwin13


       Running handlers:
       [2016-12-19T08:23:35-08:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-12-19T08:23:35-08:00] ERROR: Exception handlers complete
       Chef Client failed. 1 resources updated in 15 seconds
       [2016-12-19T08:23:35-08:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-12-19T08:23:35-08:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-12-19T08:23:35-08:00] ERROR: homebrew_package[git] (workstation::git line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
       ---- Begin output of brew upgrade git ----
       STDOUT:
       STDERR: Error: git not installed
       ---- End output of brew upgrade git ----
       Ran brew upgrade git returned 1
       [2016-12-19T08:23:35-08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Cannot create directory[/opt/homebrew-cask] when running chef-client as a non-root user

When ensuring directories, the cask recipe makes the assumption that chef-client has been run either as root or with elevated privileges. If running chef-client in local mode as the current user, I run into the following error.

================================================================================
Error executing action `create` on resource 'directory[/opt/homebrew-cask]'
================================================================================

Chef::Exceptions::InsufficientPermissions
-----------------------------------------
Cannot create directory[/opt/homebrew-cask] at /opt/homebrew-cask due to insufficient permissions

Resource Declaration:
---------------------
# In /Users/glevine/.chef/local-mode-cache/cache/cookbooks/homebrew/recipes/cask.rb

 31: directory '/opt/homebrew-cask' do
 32:   owner node['homebrew']['owner'] || homebrew_owner
 33:   mode 00775
 34: end
 35: 

Compiled Resource:
------------------
# Declared in /Users/glevine/.chef/local-mode-cache/cache/cookbooks/homebrew/recipes/cask.rb:31:in `from_file'

directory("/opt/homebrew-cask") do
  action :create
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  path "/opt/homebrew-cask"
  declared_type :directory
  cookbook_name "homebrew"
  recipe_name "cask"
  homebrew_owner 501
  owner 501
  mode 509
end

[2015-04-28T23:06:01-04:00] INFO: Running queued delayed notifications before re-raising exception
[2015-04-28T23:06:01-04:00] DEBUG: Re-raising exception: Chef::Exceptions::InsufficientPermissions - directory[/opt/homebrew-cask] (homebrew::cask line 31) had an error: Chef::Exceptions::InsufficientPermissions: Cannot create directory[/opt/homebrew-cask] at /opt/homebrew-cask due to insufficient permissions

The java cookbook includes the homebrew::cask recipe in its homebrew recipe (https://github.com/agileorbit-cookbooks/java/blob/master/recipes/homebrew.rb). So when installing Java using Homebrew, it seems like it is a requirement to run chef-client as root. This has two smells to me:

  1. The user is effectively required to install Java as root, which runs counter to how Homebrew is designed.
  2. Even if I wrote a wrapper script to create the directory before calling chef-client, then I would still run into this issue anytime I tried to use the java community cookbook.

The java cookbook is just an example, though. This could be true for any dependent cookbook. But it is especially difficult to work around when trying to use community cookbooks.

Maybe this could be passed off as an issue with the java cookbook. But it just feels like cookbooks dependent on the homebrew cookbook are not expecting this cookbook to behave this way -- if being permission agnostic is a goal.

Support git based homebrew taps

homebrew supports custom taps that can be installed from any repo using a command like:

brew tap my-internal/tap [email protected]:org/homebrew-my-internal.git

The homebrew cookbook does not support this functionality at the moment.

I wrote some code to fix this on my own private fork, but it wasn't backwards compatible as I changed the ['homebrew']['taps'] attribute into an array of hashes like this:

[
        { "name": "caskroom/cask" },
        { "name": "homebrew/dupes" },
        { "name": "homebrew/completions" },
        { "name": "custom-internal/tap",
          "repo": "[email protected]:org/homebrew-custom-internal.git"
        }
]

fail to install brew-cask with homebrew_package

Cookbook version

1.13.0

Chef-client version

12.12.15

Platform Details

osx 10.10.5 - Darwin Kernel Version 14.5.0

Scenario:

i have a list of packages that i want to install using the cookbook, including another list of casks

Steps to Reproduce:

this is my recipe calling homebrew -

include_recipe 'homebrew'
include_recipe 'homebrew::cask'

unless node['databag_items']['packages']['darwin']['install'].nil?
  node['databag_items']['packages']['darwin']['install'].each do |install|
    package install
  end
end

unless node['databag_items']['packages']['darwin']['cask'].nil?
  node['databag_items']['packages']['darwin']['cask'].each do |install|
    homebrew_cask install
  end
end

Expected Result:

expecting the packages/casks to get installed

Actual Result:

output of --why-run

* homebrew_package[brew-cask] action install

  ================================================================================
  Error executing action `install` on resource 'homebrew_package[brew-cask]'
  ================================================================================

  NoMethodError
  -------------
  undefined method `chomp' for nil:NilClass

  Cookbook Trace:
  ---------------
  /Users/cwong/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:94:in `get_version_from_formula'
  /Users/cwong/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:74:in `current_installed_version'
  /Users/cwong/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:44:in `load_current_resource'
  /Users/cwong/.chef/local-mode-cache/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:41:in `run_action'

  Resource Declaration:
  ---------------------
  # In /Users/cwong/.chef/local-mode-cache/cache/cookbooks/homebrew/recipes/cask.rb

   23: package 'brew-cask'
   24:

  Compiled Resource:
  ------------------
  # Declared in /Users/cwong/.chef/local-mode-cache/cache/cookbooks/homebrew/recipes/cask.rb:23:in `from_file'

  homebrew_package("brew-cask") do
    package_name "brew-cask"
    action [:install]
    retries 0
    retry_delay 2
    default_guard_interpreter :default
    declared_type :package
    cookbook_name "homebrew"
    recipe_name "cask"
  end

node["homebrew"]["user"] validation fails on non OSX hosts

Cookbook version

5.0.1

Chef-client version

12.21.4

Platform Details

Ubuntu 16.04

Scenario:

Running chef client on an Ubuntu 16 machine that uses a recipe that has a dependency to homebrew 5.0.1 but no node["homebrew"]["user"]

Steps to Reproduce:

Create a cookbook that has a dependency on homebrew, run it on an ubuntu 16.04 machine without setting the node["homebrew"]["user"] attribute

Expected Result:

Should not install homebrew but not fail

Actual Result:

Fails with error message Homebrew owner is 'root' which is not supported

After the release of 5.0.x, our recipes that are depending on hombrew can not be run on ubuntu 14 or 16 hosts, as the validation of the user to run as fails. Prior to this update the recipe ran fine on all platforms.

This attribute should not be neccessary on hosts that are not concerned with hombrew, otherwise transient dependency concerns are 'leaked' up the chain.

Error executing action `create` on resource 'template[/etc/profile.d/jdk.sh]'

================================================================================
Error executing action create on resource 'template[/etc/profile.d/jdk.sh]'
================================================================================

Chef::Exceptions::FileNotFound
------------------------------
Cookbook 'java' (2.0.1) does not contain a file at any of these locations:
  templates/centos-7.5.1804/jdk.sh.erb
  templates/centos/jdk.sh.erb
  templates/default/jdk.sh.erb
  templates/jdk.sh.erb

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/java/recipes/set_java_home.rb

 23: template '/etc/profile.d/jdk.sh' do
 24:   source 'jdk.sh.erb'
 25:   mode '0755'
 26: end
 27:

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/java/recipes/set_java_home.rb:23:in `from_file'

template("/etc/profile.d/jdk.sh") do
  action [:create]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  source "jdk.sh.erb"
  declared_type :template
  cookbook_name "java"
  recipe_name "set_java_home"
  mode "0755"
  atomic_update true
  path "/etc/profile.d/jdk.sh"
end

[2018-05-25T10:47:29+00:00] INFO: Running queued delayed notifications before re-raising exception
chef-client --version
Chef: 12.8.1

Running handlers:
[2018-05-25T10:47:29+00:00] ERROR: Running exception handlers
Running handlers complete
[2018-05-25T10:47:29+00:00] ERROR: Exception handlers complete
Chef Client failed. 2 resources updated in 07 seconds
[2018-05-25T10:47:29+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2018-05-25T10:47:29+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-05-25T10:47:29+00:00] ERROR: template[/etc/profile.d/jdk.sh] (java::set_java_home line 23) had an error: Chef::Exceptions::FileNotFound: Cookbook 'java' (2.0.1) does not contain a file at any of these locations:
templates/centos-7.5.1804/jdk.sh.erb
templates/centos/jdk.sh.erb
templates/default/jdk.sh.erb
templates/jdk.sh.erb
[2018-05-25T10:47:29+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

undefined method `full' for Chef::Resource::HomebrewTap

🗣️ Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

👻 Brief Description

A clear and concise description of what the bug is.

When using the homebrew_tap resource we get the following error

         * homebrew_tap[chef/chef] action tap
           
           ================================================================================
           Error executing action `tap` on resource 'homebrew_tap[chef/chef]'
           ================================================================================
           
           NoMethodError
           -------------
           undefined method `full' for Chef::Resource::HomebrewTap
           
           Resource Declaration:
           ---------------------
           # In /Users/Shared/kitchen/cache/cookbooks/lab_build/recipes/chef_environment.rb

I've also tried executing the install_taps recipe and get the following similar errors

       Recipe: homebrew::install_taps
         * homebrew_tap[chef/chef] action tap
           
           ================================================================================
           Error executing action `tap` on resource 'homebrew_tap[chef/chef]'
           ================================================================================
           
           NoMethodError
           -------------
           undefined method `full' for Chef::Resource::HomebrewTap

🥞 Cookbook version

Version of the cookbook where you are encountering the issue.

5.3.0

👩‍🍳 Chef-Infra Version

Tested on

21.12.720 and 21.9.613

🎩 Platform details

macOS 10.15.7 Catalina

Steps To Reproduce

Steps to reproduce the behavior:

kitchen converge a recipe using homebrew_tap such as

homebrew_tap `chef/chef`

🚓 Expected behavior

Expected tap to work

➕ Additional context

--full does not seem to be an option in homebrew's documentation anymore: https://docs.brew.sh/Taps

When trying to execute it we get the following:

brew tap --full chef/chef
Error: Calling the --full switch is disabled! There is no replacement.

Associated Homebrew PRs where this was removed:
Homebrew/brew#11337
Homebrew/brew#11328

Homebrew Cask's default Caskroom location has changed

As per Homebrew/homebrew-cask#21857 the default location for the Caskroom has changed to /usr/local/Caskroom instead of /opt/homebrew-cask/Caskroom.

The cask recipe will always create the old directory: https://github.com/chef-cookbooks/homebrew/blob/ab010defa6d3cc4cbf9c83c4c097f6ac87ef7e1f/recipes/cask.rb#L29-L38

As long as the old directory exists cask will show a warning that you should migrate to the new location but it will keep using the old location. Since this recipe always creates the old location cask will keep on installing in the old location even if you have migrated to the new one.

One option would be to just change the directories in the cask recipe but I'm actually not sure if those directories should be created by that recipe. I'd think that cask would create them if they don't exist yet. But I'd have to investigate that.

undefined method `casked' for nil:NilClass

Having trouble using the cask lwrp - guessing something broke with the recent version update

================================================================================
      Error executing action `run` on resource 'execute[installing cask iterm2]'
      ================================================================================

      NoMethodError
      -------------
      undefined method `casked' for nil:NilClass

      Cookbook Trace:
      ---------------
      /var/folders/7f/9lj81yv94xb8p9_n7fntfn34xs6f50/T/cookbooks.9Fro95aW/site-cookbooks/homebrew/providers/cask.rb:40:in `block (3 levels) in class_from_file'

      Resource Declaration:
      ---------------------
      # In /var/folders/7f/9lj81yv94xb8p9_n7fntfn34xs6f50/T/cookbooks.9Fro95aW/site-cookbooks/homebrew/providers/cask.rb

       37:   execute "installing cask #{new_resource.name}" do
       38:     command "/usr/local/bin/brew cask install #{new_resource.name} #{new_resource.options}"
       39:     user homebrew_owner
       40:     not_if { @cask.casked }
       41:   end
       42: end

Cask resource seems to fail to compile on some non-darwin machine

Cookbook version

5.0.1

Chef-client version

13.8.5 (ruby 2.4.0)

Platform Details

CentOS Linux release 7.3.1611 (Core)

Scenario:

When trying to run a basic ChefSpec test for CentOS of a cookbook that does only include homebrew has a dependency.

Steps to Reproduce:

Create a ChefSpec test as below:

require 'spec_helper'
describe 'nexus3::default' 
  context 'When all attributes are default, on centos 7.2.1511' do
    let(:chef_run) do
      ::ChefSpec::SoloRunner.new(platform: 'centos', version:  '7.2.1511').converge(described_recipe)
    end
    it 'converges successfully' do
      expect { chef_run }.to_not raise_error
    end
  end
end

Expected Result:

No error.

Actual Result:

  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:431:in `_pv_is'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:107:in `block (2 levels) in validate'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:104:in `each'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:104:in `block in validate'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:94:in `each'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/params_validate.rb:94:in `validate'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:473:in `validate'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:677:in `coerce_and_validate'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:658:in `input_to_stored_value'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:131:in `initialize'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:51:in `new'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/property.rb:51:in `derive'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/properties.rb:147:in `property_type'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/properties.rb:127:in `property'
  # /tmp/chefspec20180309-7124-zbtmhnfile_cache_path/cookbooks/homebrew/resources/cask.rb:25:in `class_from_file'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/from_file.rb:42:in `class_eval'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/mixin/from_file.rb:42:in `class_from_file'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/resource/lwrp_base.rb:58:in `build_from_file'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:253:in `load_lwrp_resource'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:238:in `block in load_lwrps_from_cookbook'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:237:in `each'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:237:in `load_lwrps_from_cookbook'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:143:in `block in compile_lwrps'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:142:in `each'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:142:in `compile_lwrps'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:75:in `compile'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/run_context.rb:191:in `load'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chef-13.8.5/lib/chef/client.rb:513:in `setup_run_context'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chefspec-7.1.2/lib/chefspec/solo_runner.rb:119:in `converge'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chefspec-7.1.2/lib/chefspec/server_runner.rb:44:in `converge'
  # ./spec/unit/recipes/default_spec.rb:30:in `block (3 levels) in <top (required)>'
  # ./spec/unit/recipes/default_spec.rb:34:in `block (4 levels) in <top (required)>'
  # /home/jenkins/.gem/ruby/2.4.0/gems/chefspec-7.1.2/lib/chefspec/expect_exception.rb:15:in `matches?'
  # ./spec/unit/recipes/default_spec.rb:34:in `block (3 levels) in <top (required)>'

@tas50 I'm really sorry to contact you again just after a release, but I think this might be related to 39c0188#diff-787cb5c90e5144bfc53079ddc72d80c2R25. Personnally I don't use homebrew, but just having it as a dependency break the tests.

Please also note that on my workstation (not my Jenkins machine) with the same gems and cookbooks it works fine :D (archlinux over WSL - ruby 2.5.0)

Package resources crash Chef 13.2

Cookbook version

4.2.0

Chef-client version

$ chef --version
Chef Development Kit Version: 2.0.28
chef-client version: 13.2.20
delivery version: master (17c1b0fed9be4c70f69091a6d21a4cbf0df60a23)
berks version: 6.2.0
kitchen version: 1.16.0
inspec version: 1.31.1

Platform Details

macOS Sierra 10.12.6

Scenario:

I'm trying to install a Homebrew package, but the package resource causes Chef to crash.

Steps to Reproduce:

Create a recipe consisting of:

package 'p7zip'

Run it using the command:

chef-client --local-mode --runlist 'homecooked::test'

Expected Result:

The p7zip package is installed.

Actual Result:

================================================================================
Recipe Compile Error in /Users/adam/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb
================================================================================

NoMethodError
-------------
undefined method `find' for Chef::Platform:Class

Cookbook Trace:
---------------
  /Users/adam/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:26:in `<top (required)>'

Relevant File Content:
----------------------
/Users/adam/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:

 19:  # limitations under the License.
 20:  #
 21:  # cookbook libraries are unconditionally included if the cookbook is
 22:  # present on a node. This approach should avoid creating this class if
 23:  # the node already has Chef::Provider::Package::Homebrew, such as with
 24:  # Chef 12.
 25:  # https://github.com/chef/chef-rfc/blob/master/rfc016-homebrew-osx-package-provider.md
 26>> unless defined?(Chef::Provider::Package::Homebrew) && Chef::Platform.find('mac_os_x', nil)[:package] == Chef::Provider::Package::Homebrew
 27:    require 'chef/provider/package'
 28:    require 'chef/resource/package'
 29:    require 'chef/platform'
 30:    require 'chef/mixin/shell_out'
 31:  
 32:    class Chef
 33:      class Provider
 34:        class Package
 35:          # Package

System Info:
------------
chef_version=13.2.20
platform=mac_os_x
platform_version=10.12.6
ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin14]
program_name=chef-client worker: ppid=3963;start=08:29:46;
executable=/opt/chefdk/bin/chef-client


Running handlers:
[2017-07-29T08:30:02+09:30] ERROR: Running exception handlers
[2017-07-29T08:30:02+09:30] ERROR: Running exception handlers
Running handlers complete
[2017-07-29T08:30:02+09:30] ERROR: Exception handlers complete
[2017-07-29T08:30:02+09:30] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 15 seconds
[2017-07-29T08:30:02+09:30] FATAL: Stacktrace dumped to /Users/adam/.chef/local-mode-cache/cache/chef-stacktrace.out
[2017-07-29T08:30:02+09:30] FATAL: Stacktrace dumped to /Users/adam/.chef/local-mode-cache/cache/chef-stacktrace.out
[2017-07-29T08:30:02+09:30] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-07-29T08:30:02+09:30] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-07-29T08:30:02+09:30] ERROR: undefined method `find' for Chef::Platform:Class
[2017-07-29T08:30:02+09:30] ERROR: undefined method `find' for Chef::Platform:Class
[2017-07-29T08:30:02+09:30] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
[2017-07-29T08:30:02+09:30] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

/Users/adam/.chef/local-mode-cache/cache/chef-stacktrace.out

Generated at 2017-07-29 08:30:02 +0930
NoMethodError: undefined method `find' for Chef::Platform:Class
/Users/adam/.chef/local-mode-cache/cache/cookbooks/homebrew/libraries/homebrew_package.rb:26:in `<top (required)>'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:224:in `load'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:224:in `block in load_libraries_from_cookbook'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:220:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:220:in `load_libraries_from_cookbook'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:101:in `block in compile_libraries'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:100:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:100:in `compile_libraries'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context/cookbook_compiler.rb:72:in `compile'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/run_context.rb:192:in `load'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:513:in `setup_run_context'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:281:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:291:in `block in fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:244:in `block in run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:232:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `loop'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:441:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:59:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/bin/chef-client:26:in `<top (required)>'
/usr/local/bin/chef-client:263:in `load'
/usr/local/bin/chef-client:263:in `<main>'

Increase the shell-out timeout to the homebrew package provider

Installing gcc46 takes more than 600s, so the shell-out times out on me:

           ================================================================================

           Error executing action `install` on resource 'package[gcc46]'

       ================================================================================


       Mixlib::ShellOut::CommandTimeout
           --------------------------------
           Command timed out after 600s:
           Command execeded allowed execution time, process terminated
           ---- Begin output of brew install  gcc46 ----

Please increase the timeout value for the shell-out of the homebrew package provider.

For your information, manually installing the gcc46 package takes 19.7 minutes:

default-osx-109:~ vagrant$ brew install gcc46
==> Downloading http://ftpmirror.gnu.org/gcc/gcc-4.6.4/gcc-4.6.4.tar.bz2
Already downloaded: /Library/Caches/Homebrew/gcc46-4.6.4.tar.bz2
==> ../configure --build=x86_64-apple-darwin13.3.0 --prefix=/usr/local/Cellar/gc
==> make bootstrap
==> make install
🍺  /usr/local/Cellar/gcc46/4.6.4: 1009 files, 108M, built in 19.7 minutes

Package Library Efficiency

So the fix I made to pull package information from Homebrew as JSON works, but brew is called seven times. It's probably no big deal, but it's redundant. I will fix this by storing the first result in an instance variable so we only call Homebrew once per package.

==> default:   * homebrew_package[homebrew/php/composer] action install
==> default: [2016-01-26T17:15:14-08:00] INFO: Processing homebrew_package[homebrew/php/composer] action install (homebrew::install_formulas line 29)
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Providers for generic homebrew_package resource enabled on node include: [Chef::Provider::Package::Homebrew]
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Provider for action install on resource homebrew_package[homebrew/php/composer] is Chef::Provider::Package::Homebrew
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Found Homebrew owner vagrant; executing `brew` commands as them
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:14-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:15-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:16-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:16-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:16-08:00] DEBUG: Getting Package info for info for homebrew/php/composer
==> default: [2016-01-26T17:15:16-08:00] DEBUG: Executing 'brew info homebrew/php/composer --json=v1' as vagrant
==> default: [2016-01-26T17:15:17-08:00] DEBUG: homebrew_package[homebrew/php/composer] homebrew/php/composer not installed, installing 1.0.0-alpha11
==> default: [2016-01-26T17:15:17-08:00] DEBUG: Executing 'brew install  homebrew/php/composer' as vagrant

"user homebrew_owner" breaks Cask on Mountain Lion

When specifying a non-root user for Cask on Mountain Lion, the following error is produced:

STDERR: Error: Empty result parsing plist output from command.
         command was:
         ["/usr/bin/hdiutil", "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", #<Pathname:/Library/Caches/Homebrew/whatever.dmg>]
         output we attempted to parse:
         hdiutil: mount failed - Device not configured

Everything works fine and dandy with the cookbook running inside of root's bootstrap context.

Incorrect permissions on /opt/homebrew-cask and subfolders

When installing the java7 cask, I bumped into permission errors on /opt/homebrew-cask folder and subfolders.

STDERR: Error: Permission denied - /opt/homebrew-cask/Caskroom/java7

This folder structure was owned by root, not the Homebrew owner.

Looking at the Pivotal Sprout Cask recipe, I noticed they set the permissions on this folder explicitely to the Homebrew owner, in their case the current user.

The cask recipe needs to be extended with a similar setup. I validated manually that setting the permissions on the folder fixed the installation process of the cask.

Running as root gets you silent failures and misinformation

This is homebrew's behavior when you run as root:

$ sudo brew install nginx
Cowardly refusing to `sudo brew install'
Kernel.exit
$ echo $?
1

Yet this is what you see when you run chef-solo when you have something like:

package "nginx" and run chef as root

the output is:

[2012-07-11T19:42:27+00:00] INFO: Processing package[nginx] action install (packages::default line 4)
[2012-07-11T19:42:28+00:00] INFO: package[nginx] installed version 1.2.2

but actually:

$ brew list | grep nginx

This is with homebrew 0.9.2 and latest rev of this repo.

Something screwy is going on in get_response_from_command where it's not picking up this failure. I'm guessing it might have something to do with it swallowing stderr although I can't understand how it misses the non-zero exit code.

Since package doesn't seem to take a user attribute I'm now trying to think of alternate solutions. At the very least perhaps the homebrew package resource could blow up loudly if it is ever run as root.

Travis build hasn't been green for 9+ months

Cookbook version

2.1.2

Chef-client version

chef-client version: 12.16.42

Platform Details

Worker information
hostname: travis-worker-gce-org-prod4-12:22f9717d-713f-472c-8fb8-cbba3ffc3973
version: v2.5.0 https://github.com/travis-ci/worker/tree/da3a43228dffc0fcca5a46569ca786b22991979f
instance: testing-gce-da39621e-82c3-4dbc-83f4-1c23c5b0bda2:travis-ci-sugilite-trusty-1471824869

Scenario:

A green build of master so that one can submit pull-requests with confidence that the test suite is valid.

Steps to Reproduce:

Submit a PR with no code changes, the build fails:

Expected Result:

CI should succeed on master: https://travis-ci.org/chef-cookbooks/homebrew/builds

The last green build of master was: https://travis-ci.org/chef-cookbooks/homebrew/builds/119385581

Actual Result:

Every build in the last 9 months as a PR or on the master branch have failed.

Perhaps the travis CI could be configured to test against macOS: https://docs.travis-ci.com/user/osx-ci-environment/

homebrew_cask LWRP fails when checking if package is already installed!

Chef Client version 12.4.3

Run output:

    * execute[installing cask spotify] action run

      ================================================================================
      Error executing action `run` on resource 'execute[installing cask spotify]'
      ================================================================================

      NoMethodError
      -------------
      undefined method `casked' for nil:NilClass

      Cookbook Trace:
      ---------------
      /var/chef/cache/cookbooks/homebrew/providers/cask.rb:40:in `block (3 levels) in class_from_file'

      Resource Declaration:
      ---------------------
      # In /var/chef/cache/cookbooks/homebrew/providers/cask.rb

       37:   execute "installing cask #{new_resource.name}" do
       38:     command "/usr/local/bin/brew cask install #{new_resource.name} #{new_resource.options}"
       39:     user homebrew_owner
       40:     not_if { @cask.casked }
       41:   end
       42: end

      Compiled Resource:
      ------------------
      # Declared in /var/chef/cache/cookbooks/homebrew/providers/cask.rb:37:in `block in class_from_file'

      execute("installing cask spotify") do
        action [:run]
        retries 0
        retry_delay 2
        default_guard_interpreter :execute
        command "/usr/local/bin/brew cask install spotify "
        backup 5
        returns 0
        user "nick"
        declared_type :execute
        cookbook_name "workstation"
        homebrew_owner "nick"
        not_if { #code block }
      end


    ================================================================================
    Error executing action `install` on resource 'homebrew_cask[spotify]'
    ================================================================================

    NoMethodError
    -------------
    execute[installing cask spotify] (/var/chef/cache/cookbooks/homebrew/providers/cask.rb line 37) had an error: NoMethodError: undefined method `casked' for nil:NilClass

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/homebrew/providers/cask.rb:40:in `block (3 levels) in class_from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/workstation/recipes/packages.rb

     42:   homebrew_cask p
     43: end

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/workstation/recipes/packages.rb:42:in `block in from_file'

    homebrew_cask("spotify") do
      action [:install]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      declared_type :homebrew_cask
      cookbook_name "workstation"
      recipe_name "packages"
    end


Running handlers:
[2015-09-27T15:02:53-04:00] ERROR: Running exception handlers
Running handlers complete
[2015-09-27T15:02:53-04:00] ERROR: Exception handlers complete
Chef Client failed. 1 resources updated in 10.01444 seconds
[2015-09-27T15:02:53-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-09-27T15:02:53-04:00] ERROR: homebrew_cask[spotify] (workstation::packages line 42) had an error: NoMethodError: execute[installing cask spotify] (/var/chef/cache/cookbooks/homebrew/providers/cask.rb line 37) had an error: NoMethodError: undefined method `casked' for nil:NilClass
[2015-09-27T15:02:53-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Installing casks from a URL

Cookbook version

4.3.0

Chef-client version

13.6.4

Platform Details

macOS 'High Sierra' 10.13.2 (17C205)

Scenario:

Installing a cask from a URL fails

Steps to Reproduce:

Trying this fails from a Chef cookbook:

homebrew_cask 'https://raw.githubusercontent.com/caskroom/homebrew-cask/3c3268942ff163d917245fbc68d26a5bcddf91de/Casks/virtualbox.rb'

Expected Result:

It should install. The (raw) command itself works:

/usr/local/bin/brew cask install 'https://raw.githubusercontent.com/caskroom/homebrew-cask/3c3268942ff163d917245fbc68d26a5bcddf91de/Casks/virtualbox.rb'

Actual Result:

The error reported is:

================================================================================
Recipe Compile Error in /Users/paul.hanssen/.chef/state/cache/cookbooks/sf_macos/recipes/developer.rb
================================================================================

Chef::Exceptions::ValidationFailed
----------------------------------
Option name's value https://raw.githubusercontent.com/caskroom/homebrew-cask/3c3268942ff163d917245fbc68d26a5bcddf91de/Casks/virtualbox.rb does not match regular expression /^[\w\/-]+$/

I believe the error occurs in the 'cask.rb' resource i.e.

property :name, String, regex: %r{^[\w/-]+$}, name_property: true # ~FC108

package upgrade doesn't install if not installed

According to http://docs.getchef.com/resource_homebrew_package.html#actions package 'mysql' action :upgrade end should install the package if it isn't installed, but this is not the case:

[…]
    ---- Begin output of brew upgrade mtr ----
    STDOUT:
    STDERR: Error: mtr not installed
    ---- End output of brew upgrade mtr ----
[…]

Maybe running and parsing brew info --json=v1 mtr before installing or upgrading would be a solution? Then we could get rid of the whole stacktrace and the need to use ignore_failure true because we're installing applications which is already installed.

If the 'installed' array is empty it's not installed:

$ brew info --json=v1 mtr | jq '.[0].installed'
[]

and if it's not empty it lists the version installed:

$ brew info --json=v1 jq | jq '.[0].installed'
[
  {
    "version": "1.4",
    "used_options": [],
    "built_as_bottle": null,
    "poured_from_bottle": false
  }
]

brew install fails because sudo chef-client

Cookbook version

2.1.2

Chef-client version

12.5.1

Platform Details

Mac OSX

Scenario:

Bootstrapping a new node fails when I attempt to install packages because chef-client is running as sudo/root and as of November 1st, 2016 Homebrew has disabled running brew with root. This also occurs even when I have default['homebrew']['owner'] = 'my username'

Homebrew/brew@eabdbde

Steps to Reproduce:

bootstrap a node or sudo chef-client with a recipe that installs a package using brew.

Homebrew Environmental Var

Looks like this commit got merged in and is now causing issues with the homebrew_package library.

The brew bash script now populates environmental variables which the config library is dependent upon.

Homebrew/legacy-homebrew@390e327

Recipe: homebrew::install_formulas
  * homebrew_package[homebrew/php/composer] action install

    ================================================================================
    Error executing action `install` on resource 'homebrew_package[homebrew/php/composer]'
    ================================================================================

    TypeError
    ---------
    no implicit conversion of nil into String

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:94:in `version_from_formula'
    /var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:74:in `current_installed_version'
    /var/chef/cache/cookbooks/homebrew/libraries/homebrew_package.rb:44:in `load_current_resource'

Something like the following needs to be added to the homebrew_package library

  ENV['HOMEBREW_PREFIX'] = brew_cmd.stdout.chomp
  ENV['HOMEBREW_REPOSITORY'] = ENV['HOMEBREW_PREFIX']
  ENV['HOMEBREW_LIBRARY'] = ::File.join(ENV['HOMEBREW_REPOSITORY'], 'Library')
  ENV['HOMEBREW_CELLAR'] = ::File.join(ENV['HOMEBREW_PREFIX'], 'Cellar')

permissions denied running brew cask install <app_name> after fresh cask install

Cookbook version

2.1.2

Chef-client version

Chef: 12.14.89

Platform Details

OS X El Capitan Version 10.11.6

Scenario:

TLDR: /usr/local/bin/brew cask install atom is failing because it doesn't have permissions to ~/Library/Caches/Homebrew/Cask/atom

I'm running Nordstrom/chefdk_bootstrap. One of the steps is to run the homebrew::cask recipe:

Recipe: homebrew::cask
  * homebrew_tap[caskroom/cask] action tap
    * execute[tapping caskroom/cask] action run (skipped due to not_if)
     (up to date)
  * directory[/Library/Caches/Homebrew/Casks] action create (skipped due to only_if)

The install succeeds, but subsequent calls to /usr/local/bin/brew cask install <app_name> fail:

$ /usr/local/bin/brew cask install atom
==> Satisfying dependencies
complete
==> Downloading https://github.com/atom/atom/releases/download/v1.11.1/atom-mac.zip
Error: Download failed on Cask 'atom' with message: Permission denied - /Users/pkaehuae/Library/Caches/Homebrew/Cask/atom--1.11.1.zip.incomplete

The workaround is to:

$ sudo chown -R $USER ~/Library/Caches/Homebrew/

While this remediates the issue, I feel like a better fix would be to add a block similar to the one below, but for ~/Library/Caches/Homebrew/ in addition to the one listed:

https://github.com/chef-cookbooks/homebrew/blob/master/recipes/cask.rb#L23-L27

Steps to Reproduce:

  1. Run this line https://github.com/Nordstrom/chefdk_bootstrap/blob/master/recipes/mac_os_x.rb#L29 on a system that does not have Homebrew or Cask installed.
  2. Run /usr/local/bin/brew cask install atom.
  3. Verify error Error: Download failed on Cask 'atom' with message: Permission denied - /Users/pkaehuae/Library/Caches/Homebrew/Cask/atom--1.11.1.zip.incomplete
  4. Run sudo chown -R $USER ~/Library/Caches/Homebrew/
  5. Attempt atom install again: /usr/local/bin/brew cask install atom
  6. Verify success.

Expected Result:

This is successful: /usr/local/bin/brew cask install atom

Actual Result:

Error: Download failed on Cask 'atom' with message: Permission denied - /Users/pkaehuae/Library/Caches/Homebrew/Cask/atom--1.11.1.zip.incomplete

New Upstream Behavior

Today I noticed the following behavior after running brew update

==> Migrating /Library/Caches/Homebrew to /Users/bdwyer/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...

Seems to be related to Homebrew/brew@a9abbab

So what does this mean? We can probably scrub out the following:

I say we let it milk a while before we pull this, the guard resource that's already there should prevent it from causing any havoc for now 😄

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.