Giter Site home page Giter Site logo

puppetlabs / puppetlabs-powershell Goto Github PK

View Code? Open in Web Editor NEW
49.0 171.0 76.0 22.19 MB

powershell provider for the Puppet exec resource type

Home Page: forge.puppetlabs.com/puppetlabs/powershell

License: Apache License 2.0

Ruby 98.25% PowerShell 1.39% Dockerfile 0.36%
module supported

puppetlabs-powershell's Introduction

powershell

Table of Contents

  1. Overview
  2. Module Description - What the module does and why it is useful
  3. Setup - The basics of getting started with powershell
  4. Usage - Configuration options and additional functionality
  5. Reference - An under-the-hood peek at what the module is doing and how
  6. Limitations - OS compatibility, etc.
  7. License
  8. Development - Guide for contributing to the module

Overview

This module adds a new exec provider capable of executing PowerShell commands.

Module Description

Puppet provides a built-in exec type that is capable of executing commands. This module adds a powershell and pwsh provider to the exec type, which enables exec parameters, listed below. This module is particularly helpful if you need to run PowerShell commands but don't know how PowerShell is executed, because you can run PowerShell commands in Puppet without the module.

Setup

Requirements

The powershell provider requires you install Windows PowerShell and have powershell.exe available in the system PATH. Note that most Windows operating systems already have Windows PowerShell installed.

The pwsh provider requires you install PowerShell Core and make pwsh available either in the system PATH or specified in the path parameter.

For example, when you install PowerShell Core in /usr/alice/pscore, you need the following manifest:

exec { 'RESOURCENAME':
  ...
  path     => '/usr/alice/pscore',
  provider => pwsh,
}

Beginning with powershell

The powershell module adapts the Puppet exec resource to run PowerShell commands. To get started, install the module and declare 'powershell' in provider with the applicable command.

exec { 'RESOURCENAME':
  command   => 'SOMECOMMAND',
  provider  => powershell,
}

Usage

When using exec resources with the powershell or pwsh provider, the command parameter must be single-quoted to prevent Puppet from interpolating $(..).

For instance, to rename the Guest account:

exec { 'rename-guest':
  command   => '(Get-WMIObject Win32_UserAccount -Filter "Name=\'guest\'").Rename("new-guest")',
  unless    => 'if (Get-WmiObject Win32_UserAccount -Filter "Name=\'guest\'") { exit 1 }',
  provider  => powershell,
}

Note that the example uses the unless parameter to make the resource idempotent. The command is only executed if the Guest account does not exist, as indicated by unless returning 0.

Note: PowerShell variables (such as $_) must be escaped in Puppet manifests either using backslashes or single quotes.

Alternately, you can put the PowerShell code for the command, onlyif, and unless parameters into separate files, and then invoke the file function in the resource. You could also use templates and the template() function if the PowerShell scripts need access to variables from Puppet.

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

Each file is a PowerShell script that should be in the module's files/ folder.

For example, here is the script at: guest/files/rename-guest.ps1

$obj = $(Get-WMIObject Win32_UserAccount -Filter "Name='Guest'")
$obj.Rename("OtherGuest")

This has the added benefit of not requiring escaping '$' in the PowerShell code. Note that the files must have DOS linefeeds or they will not work as expected. One tool for converting UNIX linefeeds to DOS linefeeds is unix2dos.

External files and exit codes

If you are calling external files, such as other PowerShell scripts or executables, be aware that the last executed script's exitcode is used by Puppet to determine whether the command was successful.

For example, if the file C:\fail.ps1 contains the following PowerShell script:

& cmd /c EXIT 5
& cmd /c EXIT 1

and we use the following Puppet manifest:

exec { 'test':
  command   => '& C:\fail.ps1',
  provider  => powershell,
}

Then the exec['test'] resource will always fail, because the last exit code from the external file C:\fail.ps1 is 1. This behavior might have unintended consequences if you combine multiple external files.

To stop this behavior, ensure that you use explicit Exit statements in your PowerShell scripts. For example, we changed the Puppet manifest from the above to:

exec { 'test':
  command   => '& C:\fail.ps1; Exit 0',
  provider  => powershell,
}

This will always succeed because the Exit 0 statement overrides the exit code from the C:\fail.ps1 script.

Console Error Output

The PowerShell module internally captures output sent to the .NET [System.Console]::Error stream like:

exec { 'test':
  command   => '[System.Console]::Error.WriteLine("foo")',
  provider  => powershell,
}

However, to produce output from a script, use the Write- prefixed cmdlets such as Write-Output, Write-Debug and Write-Error.

Reference

Provider

Parameters

All parameters are optional.

creates

Specifies the file to look for before running the command. The command runs only if the file doesn't exist. Note: This parameter does not create a file, it only looks for one. Valid options: A string of the path to the file. Default: Undefined.

cwd

Sets the directory from which to run the command. Valid options: A string of the directory path. Default: Undefined.

command

Specifies the actual PowerShell command to execute. Must either be fully qualified or a search path for the command must be provided. Valid options: String. Default: Undefined.

environment

Sets additional environment variables to set for a command. Valid options: String, or an array of multiple options. Default: Undefined.

logoutput

Defines whether to log command output in addition to logging the exit code. If you specify 'on_failure', it only logs the output when the command has an exit code that does not match any value specified by the returns attribute. Valid options: true, false, and 'on_failure'. Default: 'on_failure'.

onlyif

Runs the exec only if the command returns 0. Valid options: String. Default: Undefined.

path

Specifies the search path used for command execution. Valid options: String of the path, an array, or a semicolon-separated list. Default: Undefined.

The pwsh provider can also use the path to find the pwsh executable.

refresh

Refreshes the command. Valid options: String. Default: Undefined.

refreshonly

Refreshes the command only when a dependent object is changed. Used with subscribe and notify metaparameters. Valid options: true, false. Default: false.

returns

Lists the expected return code(s). If the executed command returns something else, an error is returned. Valid options: An array of acceptable return codes or a single value. Default: 0.

timeout

Sets the maximum time in seconds that the command should take. Valid options: Number or string representation of a number. Default: 300. A value of 0 for this property will result in using the default timeout of 300. Inifinite timeout is not supported in this module, but large timeouts are allowed if needed.

tries

Determines the number of times execution of the command should be attempted. Valid options: Number or a string representation of a number. Default: '1'.

try_sleep

Specifies the time to sleep in seconds between tries. Valid options: Number or a string representation of a number. Default: Undefined.

unless

Runs the exec, unless the command returns 0. Valid options: String. Default: Undefined.

Limitations

  • The powershell provider is only supported on:

    • Windows Server 2008 and above

    • Windows 7 and above

  • The pwsh provider is supported on:

    • CentOS 7

    • Debian 8.7+, Debian 9

    • Fedora 27, 28

    • MacOS 10.12+

    • Red Hat Enterprise Linux 7

    • Ubuntu 14.04, 16.0.4 and 18.04

    • Windows Desktop 7 and above

    • Windows Server 2008 R2 and above

    Note that this module will not install PowerShell on these platforms. For further information see the Linux installation instructions.

  • Only supported on Windows PowerShell 2.0 and above, and PowerShell Core 6.1 and above.

  • When using here-strings in inline or templated scripts executed by this module, you must use the double-quote style syntax that begins with @" and ends with "@. The single-quote syntax that begins with @' and ends with '@ is not supported.

    Note that any external .ps1 script file loaded or executed with the call operator & is not subject to this limitation and can contain any style here-string. For instance, the script file external-code.ps1 can contain any style of here-string:

    exec { 'external-code':
      command   => '& C:\external-code.ps1',
      provider  => powershell,
    }
    

License

This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of AGPL, BSD-2, BSD-3, GPL2.0, LGPL, MIT and MPL Licensing.

Development

Puppet modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our module contribution guide.

puppetlabs-powershell's People

Contributors

chelnak avatar clairecadman avatar cyberious avatar daianamezdrea avatar david22swan avatar davids avatar eputnam avatar ferventcoder avatar glennsarti avatar gspatton avatar hunner avatar iristyle avatar jordanbreen28 avatar joshcooper avatar jpogran avatar jtappa avatar lionce avatar lukasaud avatar malikparvez avatar michaeltlombardi avatar natemccurdy avatar pdoconnell avatar pmcmaw avatar praj1001 avatar rajat-puppet avatar ramesh7 avatar randomnoun7 avatar sanfrancrisko avatar sheenaajay avatar tphoney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetlabs-powershell's Issues

Fact loading (iis_version) throws exception when IIS is not available

I noticed that fact loading for iis_version throws an exception if IIS is not enabled on a machine.
I traced the exception being thrown to this line in the puppetlabs-iis repository.

The puppet run continues like normal after this, but the exception message get set as the value for the iis_version fact as can be seen in the image below.

image

Potential Exit Code Issue

Hi Josh

I was trying to use this module today and wrote the following in my init.pp

exec { 'Import ServerManager Module':
command => 'Import-Module ServerManager; Add-WindowsFeature BitLocker',
unless => 'Import-Module ServerManager; if((Get-WindowsFeature BitLocker).Installed -eq $true) {exit 1}',
provider => powershell,
}

The issue here is that my machine doesn't have BitLocker installed on it. So the unless should not return exit 1, which would mean that the command itself should run but it never runs.

Do I need to add anything else here? If I can get this module working, then I can basically script the entire installation of a Windows 2008 and 2012 server.

Thoughts here?

Paul

add -file parameter

The powershell module runs ps scripts with -Command parameter.

e.g.
"C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe" -ExecutionPolicy Bypass -Command - < "C:\puppet-powershell-accounts.ps1"

This redirect powershell's stdin to read from a file causes the problem with PSConsoleHostReadLine search across a folder structure that finally causes the issue with high CPU utilization.

Could you add possibility to use -file instead of -command parameter?

Let me know If you need more info. I can send you a complete communication that I had with MS support.

Thanks,
Karel

Warning message on Linux agents

info: Loading downloaded plugin /var/opt/lib/pe-puppet/lib/puppet/provider/exec/powershell.rb
/var/opt/lib/pe-puppet/lib/puppet/provider/exec/powershell.rb:12: warning: already initialized constant POWERSHELL

Specify -InputFormat None

@rismoney suggested we specify -InputFormat None to ensure the powershell script doesn't block reading from stdin. Alternatively, write the script to a tempfile and use -file <path>. See comment #5 (comment)

Passing Credentials in Scripts

I've had a number of conversations with various Puppet folks about this and it remains a bit of a sticky issue, namely how do we safely handle scripts where we need to pass credentials or other sensitive information to Powershell?

The scenario here is that we have a situation where we need to give Powershell some credentials to perform some sort of work on the system. Due to restrictions we have to pass these credentials via Puppet in some fashion, e.g. we can't or don't have access to a key manager that Powershell can talk to directly. (I do understand there are other issues here as well, such as getting secrets securely passed in the catalog, but I'm setting that aside for now.)

Recent incarnations of the provider, and I think the latest version if I understanding the Powershell manager code correctly, all write a temp file to disk that contains the powershell code to be invoked. This means that if I have the credentials placed directly in the script (which generally seems the route I have to take) that I'll have written them to disk. Additionally, the exec module itself has logging that will log the command out to both the event log and the Puppet report, which will expose credentials. None of these outcomes are very good.

The approach I've tried to take is going the route of signed powershell scripts so we can invoke them with command line parameters rather than using stdin or the Powershell Manager, which doesn't allow that. This seems at the moment to side-step some of the above mentioned problems depending on how you communicate those command line parameters to the provider. However, I'd like to align with the longer-term strategy, if possible, of how Powershell scripts are invoked within the Puppet supported provider.

So...what's the best way of handling this?

exec resource throws error on a windows where PS execution policy set to Allsigned

Describe the Bug

exec resource with provider set to powershell does not work on a windows machine with powershell execution policy set to allsigned

Expected Behavior

exec resource should run and ps commands should be executed.

Steps to Reproduce

Steps to reproduce the behavior:

  1. log in to a windows machine , set ps execution policy to allsigned and execute a exec resource with provider set to powershell
  2. execution throws an error

Environment

  • PE 2019.8
  • Platform windows

Additional Context

this looks to be an issue only when provider is mentioned as "powershell" explicitly on exec resource

Suggestion: Have powershell errors report to a single event log event

Currently, it appears that when the powershell provider runs into an error in the powershell script, it writes an event log entry for each line that would output to the screen, making reading and parsing the event log tedious. Any way we can have it output the entire error to one event log, reducing the number of logs and making troubleshooting easier?

Illegal character '&' in raw string

Summary

When running an exec to install Wordpress with webpicmd, I get this error (formatted for readability):

#<RuntimeError: Illegal character '&' in raw string "

The software that you obtain using the Web Platform Installer Command Line Tool is licensed to you by its owner.
Microsoft grants you no rights for third party software. . .. ... . .. ...
Successfully loaded primary feed: https://go.microsoft.com/?linkid=9842185

Please choose a database for 'WordPress'
Selected database: 'MySQL'

Product 'Update for IIS 7.0 FastCGI' has no installers available for this platform
Product 'Update for IIS 7.0 FastCGI (KB980363)' has no installers available for this platform
Product 'Microsoft Visual C++ 2012 Redistributable Package' has no installers available for this platform

The following software is going to be installed:

EULA: 'IIS: WAS Process Model', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: WAS Configuration API', which is owned by 'Microsoft' will be turned on
EULA: '.NET 4.5 Extended with ASP.NET for Windows 8', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Static Content', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Default Document', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Directory Browsing', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: HTTP Errors', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: HTTP Logging', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Logging Tools', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Request Monitor', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Request Filtering', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Static Content Compression', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Management Console', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: CGI', which is owned by 'Microsoft' will be turned on
EULA: 'RunPHP Helper', which is owned by 'Unknown', will be downloaded from 'https://sourceforge.net/projects/phpinstallermsi/files/zip/runphp.zip/download'.
The license agreement to 'RunPHP Helper' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.
EULA: 'Web Deploy 3.5 - 2013', which is owned by 'Microsoft', will be downloaded from 'http://go.microsoft.com/fwlink/?LinkID=309497&clcid=0x409'. The license agreement to 'Web Deploy 3.5 - 2013' is available at 'http://go.microsoft.com/fwlink/?LinkId=309505&clcid=0x409'.
EULA: 'Web Deploy 3.5 without bundled SQL support', which is owned by 'Microsoft' will be installed The license agreement to 'Web Deploy 3.5 without bundled SQL support' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.
EULA: 'Web Deploy 3.5 without bundled SQL support (latest)', which is owned by 'Microsoft' will be installed The license agreement to 'Web Deploy 3.5 without bundled SQL support (latest)' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.
EULA: 'URL Rewrite 2.0', which is owned by 'Microsoft', will be downloaded from 'http://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi'. The license agreement to 'URL Rewrite 2.0' is available at 'http://download.microsoft.com/download/6/9/C/69C1195A-123E-4BE8-8EDF-371CDCA4EC6C/License_rtw.htm'.
EULA: 'MySQL Connector/Net', which is owned by 'http://mysql.llarian.net/', will be downloaded from 'http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-6.9.7.msi'. The license agreement to 'MySQL Connector/Net' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.
EULA: 'PHP 5.5.38', which is owned by 'PHP.net', will be downloaded from 'http://sourceforge.net/projects/phpinstallermsi/files/zip/php-5.5.38-nts-Win32-VC11-x86.zip/download'. The license agreement to 'PHP 5.5.38' is available at 'http://www.php.net/license/3_01.txt'.
EULA: 'Windows Cache Extension 1.3 for PHP 5.5', which is owned by 'Microsoft', will be downloaded from 'http://sourceforge.net/projects/wincache/files/wincache-1.3.7/wincachewpi-1.3.7.11-5.5-nts-vc11-x86.exe/download'. The license agreement to 'Windows Cache Extension 1.3 for PHP 5.5' is available at 'http://svn.php.net/viewvc/pecl/wincache/trunk/LICENSE?view=markup'.
EULA: 'WordPress', which is owned by 'WordPress', will be downloaded from 'https://github.com/Atomthin/WordPress_Windows_package/blob/master/wordpress-4.6.1-IIS.zip?raw=true'. The license agreement to 'WordPress' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.
EULA: 'MySQL Windows 5.1', which is owned by 'Unknown', will be downloaded from 'http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73-winx64.msi'. The license agreement to 'MySQL Windows 5.1' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.

Accepted EULA.
Starting Installation
Started downloading products..." >

c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/text.rb:155:in `block in check'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/text.rb:153:in `scan'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/text.rb:153:in `check'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/text.rb:120:in `initialize'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/parsers/treeparser.rb:46:in `new'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/parsers/treeparser.rb:46:in `parse'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/document.rb:287:in `build'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/document.rb:44:in `initialize'
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet_x/puppetlabs/powershell/powershell_manager.rb:82:in `new'
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet_x/puppetlabs/powershell/powershell_manager.rb:82:in `execute'
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/exec/powershell.rb:77:in `run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type/exec.rb:130:in `block in sync'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type/exec.rb:127:in `times'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type/exec.rb:127:in `sync'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:189:in `sync'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:114:in `sync_if_needed'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:87:in `block in perform_changes'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:86:in `each'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:86:in `perform_changes'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:20:in `evaluate'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:212:in `apply'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:228:in `eval_resource'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:151:in `call'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:151:in `block (2 levels) in evaluate'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:386:in `block in thinmark'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:385:in `thinmark'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:151:in `block in evaluate'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/graph/relationship_graph.rb:118:in `traverse'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction.rb:142:in `evaluate'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/resource/catalog.rb:222:in `block in apply'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util/log.rb:155:in `with_destination'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/transaction/report.rb:118:in `as_logging_destination'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/resource/catalog.rb:221:in `apply'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/configurer.rb:171:in `block in apply_catalog'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:223:in `block in benchmark'
c:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:222:in `benchmark'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/configurer.rb:170:in `apply_catalog'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/configurer.rb:315:in `run_internal'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/configurer.rb:186:in `block in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/context.rb:65:in `override'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet.rb:240:in `override'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/configurer.rb:185:in `run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:45:in `block (4 levels) in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent/locker.rb:21:in `lock'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:45:in `block (3 levels) in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:98:in `with_client'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:42:in `block (2 levels) in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:65:in `run_in_fork'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:41:in `block in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:179:in `call'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:179:in `controlled_run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/agent.rb:39:in `run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application/agent.rb:353:in `onetime'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application/agent.rb:331:in `run_command'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:344:in `block in run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:540:in `exit_on_fail'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:344:in `run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util/command_line.rb:128:in `run'
c:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util/command_line.rb:72:in `execute'
c:/Program Files/Puppet Labs/Puppet/puppet/bin/puppet:5:in `<main>'

... Illegal character '&' in raw string "

The software that you obtain using the Web Platform Installer Command Line Tool is licensed to you by its owner.
Microsoft grants you no rights for third party software. . .. ... . .. ...
Successfully loaded primary feed: https://go.microsoft.com/?linkid=9842185

Please choose a database for 'WordPress'
Selected database: 'MySQL'
Product 'Update for IIS 7.0 FastCGI' has no installers available for this platform
Product 'Update for IIS 7.0 FastCGI (KB980363)' has no installers available for this platform
Product 'Microsoft Visual C++ 2012 Redistributable Package' has no installers available for this platform

The following software is going to be installed:

EULA: 'IIS: WAS Process Model', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: WAS Configuration API', which is owned by 'Microsoft' will be turned on
EULA: '.NET 4.5 Extended with ASP.NET for Windows 8', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Static Content', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Default Document', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Directory Browsing', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: HTTP Errors', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: HTTP Logging', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Logging Tools', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Request Monitor', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Request Filtering', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Static Content Compression', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: Management Console', which is owned by 'Microsoft' will be turned on
EULA: 'IIS: CGI', which is owned by 'Microsoft' will be turned on

EULA: 'RunPHP Helper', which is owned by 'Unknown', will be downloaded from 'https://sourceforge.net/projects/phpinstallermsi/files/zip/runphp.zip/download'.
The license agreement to 'RunPHP Helper' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.

EULA: 'Web Deploy 3.5 - 2013', which is owned by 'Microsoft', will be downloaded from 'http://go.microsoft.com/fwlink/?LinkID=309497&clcid=0x409'.
The license agreement to 'Web Deploy 3.5 - 2013' is available at 'http://go.microsoft.com/fwlink/?LinkId=309505&clcid=0x409'.

EULA: 'Web Deploy 3.5 without bundled SQL support', which is owned by 'Microsoft' will be installed
The license agreement to 'Web Deploy 3.5 without bundled SQL support' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.

EULA: 'Web Deploy 3.5 without bundled SQL support (latest)', which is owned by 'Microsoft' will be installed
The license agreement to 'Web Deploy 3.5 without bundled SQL support (latest)' may be included with the software. You are responsible for and must separately locate, read and accept these license terms.

EULA: 'URL Rewrite 2.0', which is owned by 'Microsoft', will be downloaded from 'http://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi'.
The license agreement to 'URL Rewrite 2.0' is available at 'http://download.microsoft.com/download/6/9/C/69C1195A-123E-4BE8-8EDF-371CDCA4EC6C/License_rtw.htm'.

EULA: 'MySQL Connector/Net', which is owned by 'http://mysql.llarian.net/', will be downloaded from 'http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-6.9.7.msi'.
The license agreement to 'MySQL Connector/Net' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.

EULA: 'PHP 5.5.38', which is owned by 'PHP.net', will be downloaded from 'http://sourceforge.net/projects/phpinstallermsi/files/zip/php-5.5.38-nts-Win32-VC11-x86.zip/download'.
The license agreement to 'PHP 5.5.38' is available at 'http://www.php.net/license/3_01.txt'.

EULA: 'Windows Cache Extension 1.3 for PHP 5.5', which is owned by 'Microsoft', will be downloaded from 'http://sourceforge.net/projects/wincache/files/wincache-1.3.7/wincachewpi-1.3.7.11-5.5-nts-vc11-x86.exe/download'.
The license agreement to 'Windows Cache Extension 1.3 for PHP 5.5' is available at 'http://svn.php.net/viewvc/pecl/wincache/trunk/LICENSE?view=markup'.

EULA: 'WordPress', which is owned by 'WordPress', will be downloaded from 'https://github.com/Atomthin/WordPress_Windows_package/blob/master/wordpress-4.6.1-IIS.zip?raw=true'.
The license agreement to 'WordPress' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.

EULA: 'MySQL Windows 5.1', which is owned by 'Unknown', will be downloaded from 'http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73-winx64.msi'.
The license agreement to 'MySQL Windows 5.1' may be included with the software.
You are responsible for and must separately locate, read and accept these license terms.

Accepted EULA.
Starting Installation
Started downloading products..." Line: 1 Position: 5389 Last 80 unconsumed characters: <ReturnResult>

Here's my manifest:

class profile::wordpress::app::windows {
  $findstr  = 'c:/Windows/system32/findstr.exe'
  $webpicmd = 'c:/ProgramData/chocolatey/bin/WebpiCmd.exe'

  file { 'c:/tmp/wordpress.app':
    content => template('profile/wordpress.app.erb'),
    ensure  => file,
  }

  package { ['webpicmd', 'vcredist2012']:
    ensure   => present,
    provider => chocolatey,
  }->

  exec { 'Install Wordpress':
    command  => "$webpicmd /Install /Application:[email protected] /MySQLPassword:dummypass /AcceptEula",
    cwd      => 'c:/tmp',
    provider => powershell,
    require  => File['c:/tmp/wordpress.app'],
    timeout  => 600,
    unless   => "$webpicmd /List /ListOption:Installed | $findstr Wordpress; if ($?) { exit 0 }",
  }
}

Questions/Notes

  • Should I be able to simply use CMD > LOGFILE to get it to avoid this?
  • I could be wrong, but I couldn't find a quiet mode w/ webpicmd
  • Environment Info
    • Running in PE 2016.2
    • Windows 2012R2

Please let me know if any further info is desired.

Cant get unless exit codes to work

I am trying something like:

exec { 'download dsm client default':
  command =>  'Write-Host "hello"',
  path     => $::path,
  provider => powershell,
  timeout  => 500,
  logoutput => true,
  unless   => 'if ((get-item "C:/Windows/System32/notepad.exe").Name -eq "notepad.exe") { exit 0 }'
}

However, it does not matter what I put in to the -eq. If I leave notepad.exe in -eq and change { exit 0} to { Write-Host "hello" } - it indeed works. Prints hello when -eq is "notepad.exe" and doesn't print if -eq doesnt equal "notepad.exe"

Yet, when I incorporate this in to puppet, the cmd will not get excuted, regardless of what is in the -eq.

Any ideas whats going on here? Ive tried forcing exit codes of 1, with else statements as well.
Can't seem to get it to work correctly.

Error when using with Windows 10 Pro with Anniversary Update

Got this error while trying the new version of the module on a Windows10 Pro with the new anniversary update. Tried later on another machine without that update and everything run ok.

Version 1.6.0 works, versions >2.x fail

Any ideas?

Debug: 2016-09-02 11:58:15 +0100 C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command - is running as pid: 3532
Debug: Waited 50 milliseconds...
Debug: 2016-09-02 11:58:15 +0100 PIPE> At line:1 char:23

Debug: 2016-09-02 11:58:15 +0100 PIPE> + function New-XmlResult

Debug: 2016-09-02 11:58:15 +0100 PIPE> +                       ~

Debug: 2016-09-02 11:58:15 +0100 PIPE> Missing function body in function declaration.

Debug: 2016-09-02 11:58:15 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:15 +0100 PIPE>     + FullyQualifiedErrorId : MissingFunctionBody

Debug: 2016-09-02 11:58:15 +0100 PIPE>

Debug: Waited 50 milliseconds...
Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   param(

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>     [Parameter()]$exitcode,

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>     [Parameter()]$output,

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>     [Parameter()]$errormessage

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   )

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:35

Debug: 2016-09-02 11:58:16 +0100 PIPE> + function Invoke-PowerShellUserCode

Debug: 2016-09-02 11:58:16 +0100 PIPE> +                                   ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Missing function body in function declaration.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : MissingFunctionBody

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:9 char:11

Debug: 2016-09-02 11:58:16 +0100 PIPE> +     $Code,

Debug: 2016-09-02 11:58:16 +0100 PIPE> +           ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Missing expression after ','.

Debug: Waited 50 milliseconds...
Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   # we make our own xml because ConvertTo-Xml makes hard to parse xml ruby side

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   # and we need to be sure

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   $xml = [xml]@"

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> <ReturnResult>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   <Property Name='exitcode'>$($exitcode)</Property>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:9 char:10

Debug: 2016-09-02 11:58:16 +0100 PIPE> +     $Code,

Debug: 2016-09-02 11:58:16 +0100 PIPE> +          ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Missing ')' in function parameter list.

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:1

Debug: 2016-09-02 11:58:16 +0100 PIPE> + {

Debug: 2016-09-02 11:58:16 +0100 PIPE> + ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Missing closing '}' in statement block or type definition.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : MissingExpressionAfterToken

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: Wait object signaled
Debug: Waited 150 total milliseconds.
Debug: 2016-09-02 11:58:16 +0100 PIPE>   <Property Name='errormessage'>$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes([string]$error

Debug: 2016-09-02 11:58:16 +0100 PIPE> message)))</Property>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   <Property

Debug: 2016-09-02 11:58:16 +0100 PIPE> Name='stdout'>$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes([string]$output)))</Property>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> </ReturnResult>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> "@

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>   $xml.OuterXml

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> IsPublic IsSerial Name                                     BaseType

Debug: 2016-09-02 11:58:16 +0100 PIPE> -------- -------- ----                                     --------

Debug: 2016-09-02 11:58:16 +0100 PIPE> True     True     String                                   System.Object

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> IsPublic IsSerial Name                                     BaseType

Debug: 2016-09-02 11:58:16 +0100 PIPE> -------- -------- ----                                     --------

Debug: 2016-09-02 11:58:16 +0100 PIPE> True     True     Int32                                    System.ValueType

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:16

Debug: 2016-09-02 11:58:16 +0100 PIPE> +     $EventName,

Debug: 2016-09-02 11:58:16 +0100 PIPE> +                ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Missing expression after ','.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : MissingExpressionAfterToken

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:3

Debug: 2016-09-02 11:58:16 +0100 PIPE> +   )

Debug: 2016-09-02 11:58:16 +0100 PIPE> +   ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Unexpected token ')' in expression or statement.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : UnexpectedToken

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> Exception calling "OpenExisting" with "1" argument(s): "Empty name is not legal.

Debug: 2016-09-02 11:58:16 +0100 PIPE> Parameter name: name"

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:3

Debug: 2016-09-02 11:58:16 +0100 PIPE> +   $event = [System.Threading.EventWaitHandle]::OpenExisting($EventNam ...

Debug: 2016-09-02 11:58:16 +0100 PIPE> +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : ArgumentException

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:1 char:6

Debug: 2016-09-02 11:58:16 +0100 PIPE> +   try

Debug: 2016-09-02 11:58:16 +0100 PIPE> +      ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> The Try statement is missing its statement block.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : MissingTryStatementBlock

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PIPE> At line:163 char:1

Debug: 2016-09-02 11:58:16 +0100 PIPE> + }

Debug: 2016-09-02 11:58:16 +0100 PIPE> + ~

Debug: 2016-09-02 11:58:16 +0100 PIPE> Unexpected token '}' in expression or statement.

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

Debug: 2016-09-02 11:58:16 +0100 PIPE>     + FullyQualifiedErrorId : UnexpectedToken

Debug: 2016-09-02 11:58:16 +0100 PIPE>

Debug: 2016-09-02 11:58:16 +0100 PowerShell initialization complete for pid: 3532
Debug: Waited 50 milliseconds...
Debug: Waited 50 milliseconds...
Debug: Waited 50 milliseconds...
Debug: Waited 50 milliseconds...
...

Powershell script with parameter

How we can call powershell script with parameter.
exec
{ 'ExecuteSQL':
command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -executionpolicy remotesigned -Command C:\Utility\ExecuteSQL.ps1 -dataSource ${dataSource} -database $initialCatalog -UserName $dbadminuserid -password $dbadminpassword -SQLfilepath $databaseMSSQLScriptpath',
returns => ['0','1'],
logoutput => on_failure,
}
is not working.It send with blank paramter value

cwd param dont work as expected

After upgrade to 2.0.1 version of plugin i notice that cwd param broken, and dont change path to value.
Example script:

  exec { "cwd test":
    cwd      => 'c:/windows/',
    command  => 'get-location',
    provider =>  powershell,
  }

At 1.0.6 version all works fine.

require_relative breaks puppet 3.x running ruby 1.8.7

#74 introduced use of require_relative which breaks in our shared windows/linux puppet master environment.

The linux environment runs Puppet 3.8.6 with Ruby 1.8.7 which I understand doesn't support require_relative. Is it possible to rewrite the require to maintain support for Ruby 1.8.7?

Run script with parameters

How can I pass parameters to the script when using template as a source? Thanks

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

suggestions

well this is interesting - great job getting it out here.

A few things I was thinking about:

Number1:
Handle x64 vs x86. We should launch \sysnative\WindowsPowershell\v1.0\powershell.exe if it exists to get 64bit posh. Otherwise launch
\system32\WindowsPowershell\v1.0\powershell.exe. Otherwise launch
powershell.exe based w/o path (assume default)

Number2:
I have not looked at the exec type specifics- does it allow switches? Specifically for powershell, we should be able to launch it with different switches both user controlled and some defaults. Defaults are probably powershell.exe -inputformat none -nologo, -noninteractive, -noprofile, -executionpolicy remotesigned?

Number3:
I am not sure if this is possible- but could we use heredoc to specify a multiline command and generate a file based on it, and run that? I was thinking something like:

command => <<-EOD
$blah="foo"
$write-host $blah
EOD

or maybe use an erb and pass it to command?

Then- I think I'd want all commands executed as a script block (enclosed in curly braces)
usage:

powershell.exe -command "& {@resource[:command]}" ?

I welcome you thoughts!

Can't get module working

Hi,

i put my last hope into this module but i can't get it working. I always get the following message on the agent when run with "puppet agent --test"

Debug: Executing 'cmd.exe /c ""C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command - < "C:\Users\ADMINI~1\AppData\Local\Temp\2\puppet-powershell20130806-2388-1me684-0.ps1""'
Error: /Stage[main]//Node[w2008-01stream]/Exec[rename-guest]: Could not evaluate
: private method `split' called for nil:NilClass

The master is a ubuntu system with puppet enterprise installed (3.2.2 (Puppet Enterprise 3.0.0)).
The agent is a Windows 2008 R2 64bit with non Enterprise puppet (3.1.1) and Powershell 2.

The site.pp on the master contains the following node definition for the windows node:

node w2008-01stream {
exec { 'rename-guest':
  command   => '$(Get-WMIObject Win32_UserAccount -Filter "Name=\'guest\'").Rename("new-guest")',
  unless    => 'if (Get-WmiObject Win32_UserAccount -Filter "Name=\'guest\'") { exit 1 }',
  provider  => powershell,
}

If i run the command manually like this

C:\Users\Administrator>cmd.exe /c ""C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command - <  "C:\temp.ps""

where the file contains

$(Get-WMIObject Win32_UserAccount -Filter "Name='guest'").Rename("new-guest")

everything seems to work:

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0

Hope someone can shed some light on this.

Regards,
Michael

$env:Path not refreshed from prior actions?

I have a fairly simple manifest using chocolatey/chocolatey and puppetlabs/powershell - when I install a component that updates the Machine Path (i.e. [System.Environment]::GetEnvironmentVariable("Path","Machine")), and subsequently issue an Exec which depends on that, it fails because Powershell doesn't see the updated Path.

I've tried setting path => $::path, path => $([System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")) and various other permutations to try to force an up-to-date Path being used, to no avail.

Any magic to make this work? Thanks!

Error: /Stage[main]/Chocolatey::Install/Exec[install_chocolatey_official]: Provider powershell is not functional on this host

For various recipes I get the error: Provider powershell is not functional on this host

For example for choco:

Error: /Stage[main]/Chocolatey::Install/Exec[install_chocolatey_official]: Provider powershell is not functional on this host

The readme says:

The powershell provider requires you install Windows PowerShell and have powershell.exe available in the system PATH. Note that most Windows operating systems already have Windows PowerShell installed.

powershell is installed and works fine on these hosts. What am I missing?

elseif not recognized

I'm experiencing some weird behavior with the powershell module. I'm using version 3.7.5 on the master and agent. The agent is a Windows 2012 R2 server with powershell 4.0. I have the following template to set the A record on a Microsoft DNS server.

$dnsserver = "<%= @dns_server %>"
$containerName = "<%= @container_name %>"
$recordName = "<%= @record_name %>"
$userName = "<%= @user_name %>"
$password = "<%= @password %>"
$TTL = '<%= @ttl %>'
$recordType = "<%= @record_type %>"

if ($recordType.ToLower() -eq "a")
    {$_recordType = "MicrosoftDNS_AType"}
elseif ($recordType.ToLower() -eq "cname")
    {$_recordType = "MicrosoftDNS_CNAMEType"}
$DNSAdmin = New-ObJect System.Management.Automation.PSCredential ($userName, (ConvertTo-SecureString $password -AsPlainText -Force))
$record = Get-WmiObject -ComputerName $dnsserver -Namespace "root\MicrosoftDNS" -Class $_recordType -Filter "ContainerName='$containerName' AND OwnerName='$recordName'" -Credential $DNSAdmin
$ipaddress = (new-object net.webclient).DownloadString('http://169.254.169.254/latest/meta-data/local-ipv4')

if ($record.IPAddress -eq $ipaddress -and $record.TTL -ne $TTL)
    {$record.Modify($TTL -as [uint32])}
elseif ($record.IPAddress -ne $ipaddress)
    {$record.Modify($record.TTL, $ipaddress)}

I receive the following error when the script runs...

Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included,
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: verify that the path is correct and try again.
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: At line:1 char:1
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + elseif ($recordType.ToLower() -eq "cname")
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + ~~~~~~
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + CategoryInfo          : ObjectNotFound: (elseif:String) [], CommandNotFoundException
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + FullyQualifiedErrorId : CommandNotFoundException
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: $_recordType = "MicrosoftDNS_CNAMEType"
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
k the spelling of the name, or if a path was included,
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: verify that the path is correct and try again.
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: At line:1 char:1
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + elseif ($record.IPAddress -ne $ipaddress)
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + ~~~~~~
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + CategoryInfo          : ObjectNotFound: (elseif:String) [], CommandNotFoundException
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + FullyQualifiedErrorId : CommandNotFoundException
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: $record.Modify($record.TTL, $ipaddress)
Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: executed successfully
Notice: Finished catalog run in 22.56 seconds

The template file is in ANSI, DOS/Win line endings, and no tabs. I'm not sure what the problem may be.

add support for pe-3.2

Error: Downloaded release for joshcooper-powershell did not match expected checksum
Error: Try 'puppet help module install' for usage

Powershell usage primer

@glennsarti has some great blog content on how to write powershell execs that goes into exit codes, terminating conditions, etc. It would be great to get some of that directly into the module README, maybe linking back to the blogs for the details.

(this had been syndicated on the puppet blog, but the perforce team is housekeeping old content and trying to move things to where they might have better impact.)

Powershell is still not working on Server 2016

A simple test on server 2016 with release 2.1.0 of this module is failing:

  exec { 'test':
    command => 'write-host "test"',
    provider  => powershell,
    logoutput => true,
  }

Output:

Debug: 2017-01-13 09:30:23 +0100 C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass is running as pid: 5232
Error: Failure waiting for PowerShell process 5232 to start pipe server
Error: /Stage[main]/test/Exec[test]/returns: change from notrun to 0 failed: Failure waiting for PowerShell process 5232 to start pipe server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.