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

The powershell module's docs should use the file() function rather than template()

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • None
    • powershell
    • None
    • 1

    Description

      The puppetlabs/powershell module's README makes the excellent recommendation of putting long Powershell scripts into other files rather than having them be long inline commands in the Puppet code.

      However, the template() function is shown as the recommended way of evaluating these external files to pass them into an exec resource. I think that we should switch those examples and the recommendations to use the file() function.

      It's a bit confusing to use the template() function on something that doesn't have any ERB code in it (as is the case in all of the README's examples). The file() function ends up with the exact same result, and is arguably clearer as it's just "shipping" a file's contents from one place to another. Also, there may be some slight overheard in using the template() function due to its use of the ERB library.

      Recommendation

      Replace examples like this:

      exec { 'rename-guest':
        command   => template('guest/rename-guest.ps1'),
        onlyif    => template('guest/guest-exists.ps1'),
        provider  => powershell,
        logoutput => true,
      }
      

      ... with this:

      exec { 'rename-guest':
        command   => file('guest/rename-guest.ps1'),
        onlyif    => file('guest/guest-exists.ps1'),
        provider  => powershell,
        logoutput => true,
      }
      

      The file() works here because it is able to use the short-hand notation for finding files (e.g. <module_name>/<file_name>), just like the template() function.

      Attachments

        Issue Links

          Activity

            People

              rob Rob Reynolds
              nate.mccurdy Nate McCurdy
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support