win_chocolatey: Add -skip-scripts support (#26523)
This PR includes: - A new parameter `skip_scripts` to disable running scripts - Documentation fixes (wrt. booleans)
This commit is contained in:
parent
7d3951d065
commit
e6ecc1285c
2 changed files with 70 additions and 32 deletions
|
@ -20,10 +20,6 @@
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$result = @{
|
|
||||||
changed = $false
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = Parse-Args $args -supports_check_mode $true
|
$params = Parse-Args $args -supports_check_mode $true
|
||||||
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||||
|
|
||||||
|
@ -34,14 +30,21 @@ $version = Get-AnsibleParam -obj $params -name "version" -type "str"
|
||||||
$source = Get-AnsibleParam -obj $params -name "source" -type "str"
|
$source = Get-AnsibleParam -obj $params -name "source" -type "str"
|
||||||
$showlog = Get-AnsibleParam -obj $params -name "showlog" -type "bool" -default $false
|
$showlog = Get-AnsibleParam -obj $params -name "showlog" -type "bool" -default $false
|
||||||
$timeout = Get-AnsibleParam -obj $params -name "timeout" -type "int" -default 2700 -aliases "execution_timeout"
|
$timeout = Get-AnsibleParam -obj $params -name "timeout" -type "int" -default 2700 -aliases "execution_timeout"
|
||||||
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "present","absent","latest","reinstalled"
|
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "absent","latest","present","reinstalled"
|
||||||
$installargs = Get-AnsibleParam -obj $params -name "install_args" -type "str"
|
$installargs = Get-AnsibleParam -obj $params -name "install_args" -type "str"
|
||||||
$packageparams = Get-AnsibleParam -obj $params -name "params" -type "str"
|
$packageparams = Get-AnsibleParam -obj $params -name "params" -type "str"
|
||||||
$allowemptychecksums = Get-AnsibleParam -obj $params -name "allow_empty_checksums" -type "bool" -default $false
|
$allowemptychecksums = Get-AnsibleParam -obj $params -name "allow_empty_checksums" -type "bool" -default $false
|
||||||
$ignorechecksums = Get-AnsibleParam -obj $params -name "ignore_checksums" -type "bool" -default $false
|
$ignorechecksums = Get-AnsibleParam -obj $params -name "ignore_checksums" -type "bool" -default $false
|
||||||
$ignoredependencies = Get-AnsibleParam -obj $params -name "ignore_dependencies" -type "bool" -default $false
|
$ignoredependencies = Get-AnsibleParam -obj $params -name "ignore_dependencies" -type "bool" -default $false
|
||||||
|
$skipscripts Get-AnsibleParam -obj $params -name "skip_scripts" -type "bool" -default $false
|
||||||
|
|
||||||
if ($source) {$source = $source.Tolower()}
|
$result = @{
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($source) {
|
||||||
|
$source = $source.Tolower()
|
||||||
|
}
|
||||||
|
|
||||||
if ($upgrade)
|
if ($upgrade)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +153,8 @@ Function Choco-Upgrade
|
||||||
[bool]$ignoredependencies,
|
[bool]$ignoredependencies,
|
||||||
[Parameter(Mandatory=$false, Position=10)]
|
[Parameter(Mandatory=$false, Position=10)]
|
||||||
[int]$timeout
|
[int]$timeout
|
||||||
|
[Parameter(Mandatory=$false, Position=11)]
|
||||||
|
[bool]$skipscripts
|
||||||
)
|
)
|
||||||
|
|
||||||
if (-not (Choco-IsInstalled $package))
|
if (-not (Choco-IsInstalled $package))
|
||||||
|
@ -204,6 +209,11 @@ Function Choco-Upgrade
|
||||||
$cmd += " -ignoredependencies"
|
$cmd += " -ignoredependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($skipscripts)
|
||||||
|
{
|
||||||
|
$cmd += " --skip-scripts"
|
||||||
|
}
|
||||||
|
|
||||||
$output = invoke-expression $cmd
|
$output = invoke-expression $cmd
|
||||||
|
|
||||||
$result.rc = $LastExitCode
|
$result.rc = $LastExitCode
|
||||||
|
@ -250,6 +260,8 @@ Function Choco-Install
|
||||||
[bool]$ignoredependencies,
|
[bool]$ignoredependencies,
|
||||||
[Parameter(Mandatory=$false, Position=11)]
|
[Parameter(Mandatory=$false, Position=11)]
|
||||||
[int]$timeout
|
[int]$timeout
|
||||||
|
[Parameter(Mandatory=$false, Position=12)]
|
||||||
|
[bool]$skipscripts
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Choco-IsInstalled $package)
|
if (Choco-IsInstalled $package)
|
||||||
|
@ -316,6 +328,11 @@ Function Choco-Install
|
||||||
$cmd += " -ignoredependencies"
|
$cmd += " -ignoredependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($skipscripts)
|
||||||
|
{
|
||||||
|
$cmd += " --skip-scripts"
|
||||||
|
}
|
||||||
|
|
||||||
$results = invoke-expression $cmd
|
$results = invoke-expression $cmd
|
||||||
|
|
||||||
$result.rc = $LastExitCode
|
$result.rc = $LastExitCode
|
||||||
|
@ -342,6 +359,8 @@ Function Choco-Uninstall
|
||||||
[bool]$force,
|
[bool]$force,
|
||||||
[Parameter(Mandatory=$false, Position=4)]
|
[Parameter(Mandatory=$false, Position=4)]
|
||||||
[int]$timeout
|
[int]$timeout
|
||||||
|
[Parameter(Mandatory=$false, Position=5)]
|
||||||
|
[bool]$skipscripts
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -372,6 +391,11 @@ Function Choco-Uninstall
|
||||||
$cmd += " -params '$packageparams'"
|
$cmd += " -params '$packageparams'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($skipscripts)
|
||||||
|
{
|
||||||
|
$cmd += " --skip-scripts"
|
||||||
|
}
|
||||||
|
|
||||||
$results = invoke-expression $cmd
|
$results = invoke-expression $cmd
|
||||||
|
|
||||||
$result.rc = $LastExitCode
|
$result.rc = $LastExitCode
|
||||||
|
@ -394,11 +418,12 @@ Try
|
||||||
Choco-Install -package $package -version $version -source $source -force $force `
|
Choco-Install -package $package -version $version -source $source -force $force `
|
||||||
-installargs $installargs -packageparams $packageparams `
|
-installargs $installargs -packageparams $packageparams `
|
||||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
-ignoredependencies $ignoredependencies -timeout $timeout -skipscripts $skipscripts
|
||||||
}
|
}
|
||||||
elseif ($state -eq "absent")
|
elseif ($state -eq "absent")
|
||||||
{
|
{
|
||||||
Choco-Uninstall -package $package -version $version -force $force -timeout $timeout
|
Choco-Uninstall -package $package -version $version -force $force -timeout $timeout `
|
||||||
|
-skipscripts $skipscripts
|
||||||
}
|
}
|
||||||
elseif ($state -eq "reinstalled")
|
elseif ($state -eq "reinstalled")
|
||||||
{
|
{
|
||||||
|
@ -407,7 +432,7 @@ Try
|
||||||
Choco-Install -package $package -version $version -source $source -force $force `
|
Choco-Install -package $package -version $version -source $source -force $force `
|
||||||
-installargs $installargs -packageparams $packageparams `
|
-installargs $installargs -packageparams $packageparams `
|
||||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
-ignoredependencies $ignoredependencies -timeout $timeout -skipscripts $skipscripts
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit-Json $result
|
Exit-Json $result
|
||||||
|
|
|
@ -25,7 +25,6 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'curated'}
|
'supported_by': 'curated'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: win_chocolatey
|
module: win_chocolatey
|
||||||
|
@ -34,41 +33,37 @@ short_description: Installs packages using chocolatey
|
||||||
description:
|
description:
|
||||||
- Installs packages using Chocolatey (U(http://chocolatey.org/)).
|
- Installs packages using Chocolatey (U(http://chocolatey.org/)).
|
||||||
- If Chocolatey is missing from the system, the module will install it.
|
- If Chocolatey is missing from the system, the module will install it.
|
||||||
- List of packages can be found at U(http://chocolatey.org/packages)
|
- List of packages can be found at U(http://chocolatey.org/packages).
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the package to be installed.
|
- Name of the package to be installed.
|
||||||
required: true
|
required: yes
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the package on the system.
|
- State of the package on the system.
|
||||||
choices:
|
choices:
|
||||||
- present
|
|
||||||
- absent
|
- absent
|
||||||
- latest
|
- latest
|
||||||
|
- present
|
||||||
- reinstalled
|
- reinstalled
|
||||||
default: present
|
default: present
|
||||||
force:
|
force:
|
||||||
description:
|
description:
|
||||||
- Forces install of the package (even if it already exists).
|
- Forces install of the package (even if it already exists).
|
||||||
- Using C(force) will cause ansible to always report that a change was made.
|
- Using C(force) will cause ansible to always report that a change was made.
|
||||||
choices:
|
type: bool
|
||||||
- yes
|
default: 'no'
|
||||||
- no
|
|
||||||
default: no
|
|
||||||
upgrade:
|
upgrade:
|
||||||
description:
|
description:
|
||||||
- If package is already installed it, try to upgrade to the latest version or to the specified version.
|
- If package is already installed it, try to upgrade to the latest version or to the specified version.
|
||||||
- As of Ansible v2.3 this is deprecated, set parameter C(state) to "latest" for the same result.
|
- As of Ansible v2.3 this is deprecated, set parameter C(state) to C(latest) for the same result.
|
||||||
choices:
|
type: bool
|
||||||
- yes
|
default: 'no'
|
||||||
- no
|
|
||||||
default: no
|
|
||||||
version:
|
version:
|
||||||
description:
|
description:
|
||||||
- Specific version of the package to be installed.
|
- Specific version of the package to be installed.
|
||||||
- Ignored when C(state) is set to "absent".
|
- Ignored when C(state) is set to C(absent).
|
||||||
source:
|
source:
|
||||||
description:
|
description:
|
||||||
- Specify source rather than using default chocolatey repository.
|
- Specify source rather than using default chocolatey repository.
|
||||||
|
@ -83,17 +78,20 @@ options:
|
||||||
allow_empty_checksums:
|
allow_empty_checksums:
|
||||||
description:
|
description:
|
||||||
- Allow empty checksums to be used.
|
- Allow empty checksums to be used.
|
||||||
default: false
|
type: bool
|
||||||
|
default: 'no'
|
||||||
version_added: '2.2'
|
version_added: '2.2'
|
||||||
ignore_checksums:
|
ignore_checksums:
|
||||||
description:
|
description:
|
||||||
- Ignore checksums altogether.
|
- Ignore checksums altogether.
|
||||||
default: false
|
type: bool
|
||||||
|
default: 'no'
|
||||||
version_added: '2.2'
|
version_added: '2.2'
|
||||||
ignore_dependencies:
|
ignore_dependencies:
|
||||||
description:
|
description:
|
||||||
- Ignore dependencies, only install/upgrade the package itself.
|
- Ignore dependencies, only install/upgrade the package itself.
|
||||||
default: false
|
type: bool
|
||||||
|
default: 'no'
|
||||||
version_added: '2.1'
|
version_added: '2.1'
|
||||||
timeout:
|
timeout:
|
||||||
description:
|
description:
|
||||||
|
@ -101,36 +99,51 @@ options:
|
||||||
default: 2700
|
default: 2700
|
||||||
version_added: '2.3'
|
version_added: '2.3'
|
||||||
aliases: [ execution_timeout ]
|
aliases: [ execution_timeout ]
|
||||||
author: "Trond Hindenes (@trondhindenes), Peter Mounce (@petemounce), Pepe Barbe (@elventear), Adam Keech (@smadam813)"
|
skip_scripts:
|
||||||
|
description:
|
||||||
|
- Do not run I(chocolateyInstall.ps1) or I(chocolateyUninstall.ps1) scripts.
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
version_added: '2.4'
|
||||||
|
notes:
|
||||||
|
- Provide the C(version) parameter value as a string (e.g. C('6.1')), otherwise it
|
||||||
|
is considered to be a floating-point number and depending on the locale could
|
||||||
|
become C(6,1), which will cause a failure.
|
||||||
|
author:
|
||||||
|
- Trond Hindenes (@trondhindenes)
|
||||||
|
- Peter Mounce (@petemounce)
|
||||||
|
- Pepe Barbe (@elventear)
|
||||||
|
- Adam Keech (@smadam813)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# * Better parsing when a package has dependencies - currently fails
|
# * Better parsing when a package has dependencies - currently fails
|
||||||
# * Time each item that is run
|
# * Time each item that is run
|
||||||
# * Support 'changed' with gems - would require shelling out to `gem list` first and parsing, kinda defeating the point of using chocolatey.
|
# * Support 'changed' with gems - would require shelling out to `gem list` first and parsing, kinda defeating the point of using chocolatey.
|
||||||
|
# * Version provided not as string might be translated to 6,6 depending on Locale (results in errors)
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
# Install git
|
- name: Install git
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: git
|
name: git
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
# Upgrade installed packages
|
- name: Upgrade installed packages
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: all
|
name: all
|
||||||
state: latest
|
state: latest
|
||||||
|
|
||||||
# Install notepadplusplus version 6.6
|
- name: Install notepadplusplus version 6.6
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: notepadplusplus.install
|
name: notepadplusplus.install
|
||||||
version: '6.6'
|
version: '6.6'
|
||||||
|
|
||||||
# Install git from specified repository
|
- name: Install git from specified repository
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: git
|
name: git
|
||||||
source: https://someserver/api/v2/
|
source: https://someserver/api/v2/
|
||||||
|
|
||||||
# Uninstall git
|
- name: Uninstall git
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: git
|
name: git
|
||||||
state: absent
|
state: absent
|
||||||
|
|
Loading…
Reference in a new issue