Install and remove a program in the same Puppet declaration 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 = &quot;7z1900-${::architecture}.msi&quot;
$install_directory = 'C:/temp/'

#Create directory for installer
file { 'install_dir':
  ensure =&gt; directory,
  path   =&gt; $install_directory,
}

# Copy installer local 
file { 'Copy_7zip_installer':
  ensure =&gt; present,
  path   =&gt; &quot;${install_directory}${installer_name}&quot;,
  source =&gt; &quot;${installer_location}${installer_name}&quot;,
}

# install 7zip 
package { 'Install 7-zip':
  ensure   =&gt; present,
  provider =&gt; 'windows',
  source   =&gt; &quot;${install_directory}${installer_name}&quot;,
}

#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 =&gt; directory,
  path   =&gt; $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       =&gt; $package_path,
  path         =&gt; &quot;${install_path}${package_name}&quot;,
  extract      =&gt; true,
  extract_path =&gt; $install_path,
  cleanup      =&gt; 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   =&gt; absent,
  provider =&gt; 'windows',
  source   =&gt; &quot;${install_directory}${installer_name}&quot;,
}

# ... Configuration and setup of Azure Pipeline Agent

Is there a simple means of working around what puppet sees as a duplicate declaration?
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?