Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created January 20, 2023 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/d010a917e8754f09f9dede4f1f2591ba to your computer and use it in GitHub Desktop.
Save nickanderson/d010a917e8754f09f9dede4f1f2591ba to your computer and use it in GitHub Desktop.
CFEngine with Chocolatey on Windows

Note: Windows package management *may* be better handled via integration with Chocolatey and open source package manager for Windows similar to yum or apt-get.

  • Product Name:: 7-Zip 16.04 (x64 edition)
Version
16.04.00.0

Product Name and version (inside the MSI) can be found (or changed) using Orca. http://www.7-zip.org/a/7z1604-x64.msi

bundle agent main
{
    powershell::
    # Install Chocolatey if it's not found.
      "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned"
        contain => powershell,
        unless => fileexists("C:\ProgramData\Chocolatey\bin\choco.exe");

      "iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex"
        contain => powershell,
        unless => fileexists("C:\ProgramData\Chocolatey\bin\choco.exe");

  packages:

    windows::

      "7zip"
        package_policy => "add",
        package_method => choco;
}

body package_method choco
{
      package_changes => "individual";
      package_list_command => "C:\ProgramData\Chocolatey\bin\choco.exe list --localonly";
      package_list_version_regex => ".*\s+ (.*)";
      package_list_name_regex => "^(.*)\s+.*";
      package_installed_regex => ".*";
      package_add_command => "C:\ProgramData\Chocolatey\bin\choco.exe install -y";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment