The program I want on my VM requires 7-zip as part of the installation process but not after the install. I want to leave the VM as clean as possible by removing 7-zip after the install is done. In puppet it seems like it would be easy enough to declare once to ensure present and again later to ensure absent.

I am currently stuck with a Duplicate declaration error. In my case 7-zip but this could appear for any package.

Duplicate declaration: Package[7-Zip 19.00 (x64 edition)] is already declared

I have the code split into multiple classes but here is what is looks like in a single manifest.

$installer_location = 'puppet:///resources/'
$installer_name = "7z1900-${::architecture}.msi"
$install_directory = 'C:/temp/'

#Create directory for installer
file { 'install_dir':
  ensure => directory,
  path   => $install_directory,

# Copy installer local 
file { 'Copy_7zip_installer':
  ensure => present,
  path   => "${install_directory}${installer_name}",
  source => "${installer_location}${installer_name}",

# install 7zip 
package { 'Install 7-zip':
  ensure   => present,
  provider => 'windows',
  source   => "${install_directory}${installer_name}",

#Use 7-zip to unpack archive and do pipelines agent install
String $package_path = lookup('azure_pipelines_agent::package_source')
String $package_name = lookup('azure_pipelines_agent::package_name')
String $install_path = lookup('azure_pipelines_agent::install_path')

# Create the install directory
file { 'install-path':
ensure => directory,
  path   => $install_path,

# Copy Azure pipeline package
# Due to a bug the archive forge module requires 7-zip 
# instead of defaulting to powershell for .zip files
archive { 'extract_azure_package':
  source       => $package_path,
  path         => "${install_path}${package_name}",
  extract      => true,
  extract_path => $install_path,
  cleanup      => true,

# uninstall 7zip 
# The title (or name) of the package must match the value of the package’s DisplayName property in the registry
# https://puppet.com/docs/puppet/6.17/resources_package_windows.html
package { '7-Zip 19.00 (x64 edition)':
  ensure   => absent,
  provider => 'windows',
  source   => "${install_directory}${installer_name}",

# ... Configuration and setup of Azure Pipeline Agent

Is there a simple means of working around what puppet sees as a duplicate declaration?

1 Answer 1


I think that the simplest solution is to have the lifecycle of the 7-Zip package managed by exec resources rather than as package resources. Imagine an exec resource that installs 7-zip, lets call it install-7-zip. There is also a second puppet exec resource that uninstalls 7-zip, lets call it uninstall-7-zip.

If all of your other puppet resources that need to use 7-zip then require 'install-7-zip' and notify 'uninstall-7-zip' then they will all be actioned whilst the executable is available.

however its not a very puppet way to solve the problem. It means that even if there are no changes required, you will still be running these exec resources, and puppet will think it has changed the platform.

is repackaging the azure pipeline package a possible alternative? perhaps re-zipping it with a different compression setting? or generating a self extracting 7-zip exe instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.