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
|
||||
# POWERSHELL_COMMON
|
||||
|
||||
$result = @{
|
||||
changed = $false
|
||||
}
|
||||
|
||||
$params = Parse-Args $args -supports_check_mode $true
|
||||
$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"
|
||||
$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"
|
||||
$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"
|
||||
$packageparams = Get-AnsibleParam -obj $params -name "params" -type "str"
|
||||
$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
|
||||
$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)
|
||||
{
|
||||
|
@ -150,6 +153,8 @@ Function Choco-Upgrade
|
|||
[bool]$ignoredependencies,
|
||||
[Parameter(Mandatory=$false, Position=10)]
|
||||
[int]$timeout
|
||||
[Parameter(Mandatory=$false, Position=11)]
|
||||
[bool]$skipscripts
|
||||
)
|
||||
|
||||
if (-not (Choco-IsInstalled $package))
|
||||
|
@ -204,6 +209,11 @@ Function Choco-Upgrade
|
|||
$cmd += " -ignoredependencies"
|
||||
}
|
||||
|
||||
if ($skipscripts)
|
||||
{
|
||||
$cmd += " --skip-scripts"
|
||||
}
|
||||
|
||||
$output = invoke-expression $cmd
|
||||
|
||||
$result.rc = $LastExitCode
|
||||
|
@ -250,6 +260,8 @@ Function Choco-Install
|
|||
[bool]$ignoredependencies,
|
||||
[Parameter(Mandatory=$false, Position=11)]
|
||||
[int]$timeout
|
||||
[Parameter(Mandatory=$false, Position=12)]
|
||||
[bool]$skipscripts
|
||||
)
|
||||
|
||||
if (Choco-IsInstalled $package)
|
||||
|
@ -316,6 +328,11 @@ Function Choco-Install
|
|||
$cmd += " -ignoredependencies"
|
||||
}
|
||||
|
||||
if ($skipscripts)
|
||||
{
|
||||
$cmd += " --skip-scripts"
|
||||
}
|
||||
|
||||
$results = invoke-expression $cmd
|
||||
|
||||
$result.rc = $LastExitCode
|
||||
|
@ -342,6 +359,8 @@ Function Choco-Uninstall
|
|||
[bool]$force,
|
||||
[Parameter(Mandatory=$false, Position=4)]
|
||||
[int]$timeout
|
||||
[Parameter(Mandatory=$false, Position=5)]
|
||||
[bool]$skipscripts
|
||||
|
||||
)
|
||||
|
||||
|
@ -372,6 +391,11 @@ Function Choco-Uninstall
|
|||
$cmd += " -params '$packageparams'"
|
||||
}
|
||||
|
||||
if ($skipscripts)
|
||||
{
|
||||
$cmd += " --skip-scripts"
|
||||
}
|
||||
|
||||
$results = invoke-expression $cmd
|
||||
|
||||
$result.rc = $LastExitCode
|
||||
|
@ -394,11 +418,12 @@ Try
|
|||
Choco-Install -package $package -version $version -source $source -force $force `
|
||||
-installargs $installargs -packageparams $packageparams `
|
||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout -skipscripts $skipscripts
|
||||
}
|
||||
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")
|
||||
{
|
||||
|
@ -407,7 +432,7 @@ Try
|
|||
Choco-Install -package $package -version $version -source $source -force $force `
|
||||
-installargs $installargs -packageparams $packageparams `
|
||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout -skipscripts $skipscripts
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
|
|
|
@ -25,7 +25,6 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|||
'status': ['preview'],
|
||||
'supported_by': 'curated'}
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: win_chocolatey
|
||||
|
@ -34,41 +33,37 @@ short_description: Installs packages using chocolatey
|
|||
description:
|
||||
- Installs packages using Chocolatey (U(http://chocolatey.org/)).
|
||||
- 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:
|
||||
name:
|
||||
description:
|
||||
- Name of the package to be installed.
|
||||
required: true
|
||||
required: yes
|
||||
state:
|
||||
description:
|
||||
- State of the package on the system.
|
||||
choices:
|
||||
- present
|
||||
- absent
|
||||
- latest
|
||||
- present
|
||||
- reinstalled
|
||||
default: present
|
||||
force:
|
||||
description:
|
||||
- Forces install of the package (even if it already exists).
|
||||
- Using C(force) will cause ansible to always report that a change was made.
|
||||
choices:
|
||||
- yes
|
||||
- no
|
||||
default: no
|
||||
type: bool
|
||||
default: 'no'
|
||||
upgrade:
|
||||
description:
|
||||
- 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.
|
||||
choices:
|
||||
- yes
|
||||
- no
|
||||
default: no
|
||||
- As of Ansible v2.3 this is deprecated, set parameter C(state) to C(latest) for the same result.
|
||||
type: bool
|
||||
default: 'no'
|
||||
version:
|
||||
description:
|
||||
- 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:
|
||||
description:
|
||||
- Specify source rather than using default chocolatey repository.
|
||||
|
@ -83,17 +78,20 @@ options:
|
|||
allow_empty_checksums:
|
||||
description:
|
||||
- Allow empty checksums to be used.
|
||||
default: false
|
||||
type: bool
|
||||
default: 'no'
|
||||
version_added: '2.2'
|
||||
ignore_checksums:
|
||||
description:
|
||||
- Ignore checksums altogether.
|
||||
default: false
|
||||
type: bool
|
||||
default: 'no'
|
||||
version_added: '2.2'
|
||||
ignore_dependencies:
|
||||
description:
|
||||
- Ignore dependencies, only install/upgrade the package itself.
|
||||
default: false
|
||||
type: bool
|
||||
default: 'no'
|
||||
version_added: '2.1'
|
||||
timeout:
|
||||
description:
|
||||
|
@ -101,36 +99,51 @@ options:
|
|||
default: 2700
|
||||
version_added: '2.3'
|
||||
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:
|
||||
# * Better parsing when a package has dependencies - currently fails
|
||||
# * 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.
|
||||
# * Version provided not as string might be translated to 6,6 depending on Locale (results in errors)
|
||||
|
||||
EXAMPLES = r'''
|
||||
# Install git
|
||||
- name: Install git
|
||||
win_chocolatey:
|
||||
name: git
|
||||
state: present
|
||||
|
||||
# Upgrade installed packages
|
||||
- name: Upgrade installed packages
|
||||
win_chocolatey:
|
||||
name: all
|
||||
state: latest
|
||||
|
||||
# Install notepadplusplus version 6.6
|
||||
- name: Install notepadplusplus version 6.6
|
||||
win_chocolatey:
|
||||
name: notepadplusplus.install
|
||||
version: '6.6'
|
||||
|
||||
# Install git from specified repository
|
||||
- name: Install git from specified repository
|
||||
win_chocolatey:
|
||||
name: git
|
||||
source: https://someserver/api/v2/
|
||||
|
||||
# Uninstall git
|
||||
- name: Uninstall git
|
||||
win_chocolatey:
|
||||
name: git
|
||||
state: absent
|
||||
|
|
Loading…
Reference in a new issue