Skip to content

Commit 85d6e18

Browse files
committed
Merge branch 'master' into stable
* master: (MODULES-3468) Update README.md (MODULES-2634) PowerShell Module doesn't run template with try/catch (MODULES-2634) Fix PS try/catch in puppet 3.X (MODULES-2634) Fix tests for non-Windows agents (maint) Remove test file from repository (maint) modsync update (MODULES-2634) Rewrite try/catch acceptance tests (MODULES-2634) Add additional try/catch tests (MODULES-3347) Handle PS Verbose Output in Tests
2 parents 859bb2d + 6d5352d commit 85d6e18

File tree

5 files changed

+155
-69
lines changed

5 files changed

+155
-69
lines changed

README.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#powershell
1+
# powershell
22

3-
####Table of Contents
3+
#### Table of Contents
44

55
1. [Overview](#overview)
66
2. [Module Description - What the module does and why it is useful](#module-description)
@@ -12,20 +12,20 @@
1212
5. [Limitations - OS compatibility, etc.](#limitations)
1313
6. [Development - Guide for contributing to the module](#development)
1414

15-
##Overview
15+
## Overview
1616

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

19-
##Module Description
19+
## Module Description
2020

2121
Puppet provides a built-in `exec` type that is capable of executing commands. This module adds a `powershell` 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 the details about how PowerShell is executed, since you can technically run PowerShell commands in Puppet without the module.
2222

23-
##Setup
23+
## Setup
2424

25-
###Setup Requirements
25+
### Setup Requirements
2626
This module requires PowerShell to be installed and the `powershell.exe` to be available in the system PATH.
2727

28-
###Beginning with powershell
28+
### Beginning with powershell
2929

3030
The powershell module adapts the Puppet [exec](http://docs.puppet.com/references/stable/type.html#exec) resource to run PowerShell commands. To get started, simply install the module and declare 'powershell' in `provider` with the applicable command.
3131

@@ -36,7 +36,7 @@ exec { 'RESOURCENAME':
3636
}
3737
~~~
3838

39-
##Usage
39+
## Usage
4040

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

@@ -77,60 +77,62 @@ $obj.Rename("OtherGuest")
7777
This has the added benefit of not requiring escaping '$' in the PowerShell code. Note that the files need to have DOS linefeeds or they will not work as expected. One tool for converting UNIX linefeeds to DOS linefeeds is [unix2dos](http://freecode.com/projects/dos2unix).
7878

7979

80-
##Reference
80+
## Reference
8181

82-
####Provider
82+
#### Provider
8383
* powershell - Adapts the Puppet `exec` resource to run PowerShell commands.
8484

85-
####Parameters
85+
#### Parameters
8686
All parameters are optional.
8787

88-
#####`creates`
88+
##### `creates`
8989
Specifies the file to look for before running the command. The command will only run if the file doesn't exist. **Note: This parameter will not create a file, it will simpy look for one.** Valid options: A string of the path to the file. Default: Undefined.
9090

91-
#####`cwd`
91+
##### `cwd`
9292
Sets the directory from which to run the command. Valid options: A string of the directory path. Default: Undefined.
9393

94-
#####`command`
94+
##### `command`
9595
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.
9696

97-
#####`environment`
97+
##### `environment`
9898
Sets additional environment variables to set for a command. Valid options: String, or an array of multiple options. Default: Undefined.
9999

100-
#####`logoutput`
100+
##### `logoutput`
101101
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'.
102102

103-
#####`onlyif`
103+
##### `onlyif`
104104
Runs the exec only if the command returns 0. Valid options: String. Default: Undefined.
105105

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

109-
#####`refresh`
109+
##### `refresh`
110110
Refreshes the command. Valid options: String. Default: Undefined.
111111

112-
#####`refreshonly`
112+
##### `refreshonly`
113113
Refreshes the command only when a dependent object is changed. Used with `subscribe` and `notify` [metaparameters](http://docs.puppet.com/references/latest/metaparameter.html). Valid options: 'true', 'false'. Default: 'false'.
114114

115-
#####`returns`
115+
##### `returns`
116116
Lists the expected return code(s). An error will be returned if the executed command returns something else. Valid options: An array of acceptable return codes or a single value. Default: 0.
117117

118-
#####`timeout`
118+
##### `timeout`
119119
Sets the maximum time in seconds that the command should take. Valid options: Number or string representation of a number. Default: 300.
120120

121-
#####`tries`
121+
##### `tries`
122122
Determines the number of times execution of the command should be attempted. Valid options: Number or a string representation of a number. Default: '1'.
123123

124-
#####`try_sleep`
124+
##### `try_sleep`
125125
Specifies the time to sleep in seconds between `tries`. Valid options: Number or a string representation of a number. Default: Undefined.
126126

127-
#####`unless`
127+
##### `unless`
128128
Runs the `exec`, unless the command returns 0. Valid options: String. Default: Undefined.
129129

130-
##Limitations
130+
## Limitations
131131

132-
* Only supported on Windows Server 2003 and above, and Windows 7 and above.
132+
* Only supported on Windows Server 2008 and above, and Windows 7 and above.
133133

134-
##Development
134+
* Only supported on Powershell 2.0 and above.
135+
136+
## Development
135137

136138
Puppet Inc 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.](https://docs.puppet.com/forge/contributing.html)

lib/puppet/provider/exec/powershell.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def validatecmd(command)
9898
private
9999
def write_script(content, &block)
100100
Tempfile.open(['puppet-powershell', '.ps1']) do |file|
101-
file.write(content)
101+
file.puts(content)
102+
file.puts()
102103
file.flush
103104
yield native_path(file.path)
104105
end

0 commit comments

Comments
 (0)