Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-2267

dsc_file with dsc_ensure => 'absent' does not remove files

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • dsc

    Description

      Create a file with dsc like:

      dsc_file {'tmp_file':
        dsc_ensure          => 'present',
        dsc_type            => 'File',
        dsc_destinationpath => 'c:/windows/temp/dsc-test.txt',
        dsc_contents        => 'foo',
      }
      

      Verify it's existence

      > gc C:\Windows\Temp\dsc-test.txt
      foo
      

      Try to remove the file

      dsc_file {'tmp_file':
        dsc_ensure          => 'absent',
        dsc_type            => 'File',
        dsc_destinationpath => 'c:/windows/temp/dsc-test.txt',
      }
      

      Puppet will claim to have removed the file

      C:\source\dsc\puppetlabs-dsc [pr/32 +12 ~2 -0 !]> bundle exec puppet apply .\dsc-file-remove.pp --modulepath ..
      Notice: Compiled catalog for vagrant-2008r2.novalocal in environment production in 0.11 seconds
      Notice: /Stage[main]/Main/Dsc_file[tmp_file]/ensure: removed
      Notice: Finished catalog run in 4.16 seconds
      

      However...

      gc C:\Windows\Temp\dsc-test.txt
      foo
      

      The code generated to call DSC is clearly incorrect, given this partial output from a --trace --debug --verbose run:

      Debug: Executing 'C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command $script:ErrorActionPreference = 'Stop'
      $PuppetModulesFolder = Join-Path $env:ProgramFiles 'WindowsPowerShell\Modules\PuppetVendoredModules'
      if (!(Test-Path($PuppetModulesFolder))) {
        & cmd.exe /c mklink /d "$PuppetModulesFolder" "C:\source\dsc\puppetlabs-dsc\vendor\DSCResources" | Out-Null
      }
       
      $currentState = Get-DscLocalConfigurationManager
       
      if ($currentState.RefreshMode -ne 'Disabled') {
        throw "DSC LCM RefreshMode must be set to Disabled for Puppet to execute DSC Resources!"
      }
       
      $invokeParams = @{
        Name          = 'File'
        Method        = 'set'
        ErrorAction   = 'Continue'
        ErrorVariable = 'invokeError'
        Property      = @{
          destinationpath = 'c:/windows/temp/dsc-test.txt'
          ensure = 'present'
          type = 'File'
        }
        ModuleName = "PSDesiredStateConfiguration"
      }
       
      $result = Invoke-DscResource @invokeParams
       
      if ($currentRefreshMode) { Set-RefreshMode $currentRefreshMode }
      if ($invokeError) { throw $invokeError }
       
      switch ($invokeParams.Method) {
        'Test' {
          [bool]($result.InDesiredState)
        }
        'Set' {
          @($Null, 0) -contains $result.ReturnValue
        }
      }
      '
      Debug: True
       
      Notice: /Stage[main]/Main/Dsc_file[tmp_file]/ensure: removed
      

      Attachments

        Issue Links

          Activity

            People

              ryan.gard Ryan Gard
              ethan Ethan Brown
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support