chef / chef/effortless

Effortless: Using chef client with chocolatey resource fails

Open
#109 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
Shell
Stars
35
Forks
35
Avg merge
2d 7h
Merged PRs (30d)
8

Description

Description

I am trying to use the Effortless pattern to create a workstation cookbook for my Windows 10 machines. I am using the newly merged chef/scaffolding-chef-infra package which has support for Windows now.

The package only installs Chocolatey and then uses the chocolatey_package resource to install two applications:

  1. Visual Studio Code
  2. Firefox

When Habitat runs the package, Chocolatey is installed correctly and indeed the chocolatey_resource runs, but the following errors are thrown.

2019-07-19_16-08-55
workstation.default hook[init]:(HK):     Failures
workstation.default hook[init]:(HK):      - vscode (exited 1) - vscode not installed. An error occurred during installation:
workstation.default hook[init]:(HK):      Item has already been added. Key in dictionary: 'Path'  Key being added: 'PATH'
workstation.default hook[init]:(HK):     STDERR:
workstation.default hook[init]:(HK):     ---- End output of C:\ProgramData\chocolatey/bin/choco.exe install -y vscode ----
workstation.default hook[init]:(HK):     Ran C:\ProgramData\chocolatey/bin/choco.exe install -y vscode returned 1

Indeed the commands that have failed work correctly when run as is in an elevated PowerShell window:

mstsc_2019-07-19_16-10-16

In case the text in the image is too small to see the error is:

I did think that something strange was happening when chef-client was run in the bundled PowerSHell core, however I have installed PSCore on the machine and run the same commands and no errors are thrown.

I have seen something like this a few years ago when I wrote POSHChef. It was down to the way in which items are deserialised. If you use the built in PowerShell cmdlet ConvertFrom-JSON in which "Path" and "PATH" are both valid elements in JSON this same error will be thrown.

However if the [System.Web.Script.Serialization.JavaScriptSerializer]::DeserializeObject() is used then "Path" and "PATH" can be made to be the same thing, although it will not be merged. (https://github.com/POSHChef/POSHChef/blob/master/functions/Exported/ConvertFrom-JSONtoHashtable.ps1).

If VSCode (or any app) is installed manually then the chocolatey_resource correctly detects that the app is installed.

Chef Version

This is being installed into the package using stuartpreston/chef-client package as is version 14.11.21`.

Platform Version

Windows: 10 1903
Habitat: 0.82.0

Replication

To replicate this issue please download by my repo at https://github.com/russellseymour/effortless and build the habitat package.

Then on a Windows 10 machine (use a local one or one in Azure for example):

  • Install Habitat
  • Run a service
  • Habitat install the built package
  • Load the service

After the package has initialised it will run chef-client and the issues will be seen as above.

When I first ran this I was only installing Visual Studio Code so thought that it might be something to do with that package. To test this I added another one and it failed as well (as seen above). To try and fix VSCode I added /DontAddToPath as a paramater option to Chocolatey but this had no effect either.

Stacktrace

Stack trace is in a Gist - https://gist.github.com/russellseymour/55d71343c5d34cd6f891af37886df5ed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by building the Habitat package from the linked replication repository and inspect the chef-client initialization that invokes the chocolatey_package resource. Compare that execution with the successful elevated PowerShell commands; done means the package installs Visual Studio Code and Firefox without the duplicate Path/PATH error.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.