Compare commits
No commits in common. "a9aa1bdaafbeefc0c89ce1ef1c45dbae7487f62c" and "5ed3297984427d75b2f00a0e6c063aed71db5c06" have entirely different histories.
a9aa1bdaaf
...
5ed3297984
@ -1,96 +0,0 @@
|
|||||||
#!powershell
|
|
||||||
|
|
||||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
|
||||||
#AnsibleRequires -PowerShell Ansible.ModuleUtils.CommandUtil
|
|
||||||
|
|
||||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{
|
|
||||||
options = @{
|
|
||||||
name = @{
|
|
||||||
type = "str"
|
|
||||||
default = $null
|
|
||||||
}
|
|
||||||
state = @{
|
|
||||||
type = "str"
|
|
||||||
default = "present"
|
|
||||||
choices = ("absent", "latest", "present")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
supports_check_mode = $false
|
|
||||||
})
|
|
||||||
|
|
||||||
$name = $module.Params.name
|
|
||||||
$state = $module.Params.state
|
|
||||||
$winget = Get-ExecutablePath "winget"
|
|
||||||
$noPackageString = "No installed package found matching input criteria."
|
|
||||||
|
|
||||||
if ($name -and $id) {
|
|
||||||
$module.FailJson("name `"$name`" and id `"$id`" must not both be provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
function Test-Installed {
|
|
||||||
$command = "`"$winget`" list `"$name`""
|
|
||||||
$result = Run-Command -command $command
|
|
||||||
if ($result.rc -eq 0) {
|
|
||||||
return $true
|
|
||||||
}
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
|
|
||||||
function Test-UpgradeAvailable {
|
|
||||||
if (!(Test-Installed)) {
|
|
||||||
return $true
|
|
||||||
}
|
|
||||||
$command = "`"$winget`" list --upgrade-available `"$name`""
|
|
||||||
$result = Run-Command -command $command
|
|
||||||
if ($result.stdout.Contains($noPackageString)) {
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
return $true
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($state) {
|
|
||||||
"absent" {
|
|
||||||
if (Test-Installed) {
|
|
||||||
$command = "`"$winget`" uninstall `"$name`""
|
|
||||||
$result = Run-Command -command $command
|
|
||||||
if ($result.rc -ne 0) {
|
|
||||||
$module.Result.rc = $result.rc
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.FailJson("Failed to uninstall package `"$name`"")
|
|
||||||
}
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.Result.changed = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"latest" {
|
|
||||||
if (Test-UpgradeAvailable) {
|
|
||||||
$command = "`"$winget`" install `"$name`""
|
|
||||||
$result = Run-Command -command $command
|
|
||||||
if ($result.rc -ne 0) {
|
|
||||||
$module.Result.rc = $result.rc
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.FailJson("Failed to install package `"$name`"")
|
|
||||||
}
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.Result.changed = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"present" {
|
|
||||||
if (!(Test-Installed)) {
|
|
||||||
$command = "`"$winget`" install `"$name`""
|
|
||||||
$result = Run-Command -command $command
|
|
||||||
if ($result.rc -ne 0) {
|
|
||||||
$module.Result.rc = $result.rc
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.FailJson("Failed to install package `"$name`"")
|
|
||||||
}
|
|
||||||
$module.Result.stdout = $result.stdout
|
|
||||||
$module.Result.changed = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$module.Result.rc = 0
|
|
||||||
$module.ExitJson()
|
|
@ -1,47 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
|
||||||
module: win_winget
|
|
||||||
author:
|
|
||||||
- "Kenneth Benzie (Benie)"
|
|
||||||
short_desription: Manages packages with WinGet
|
|
||||||
description:
|
|
||||||
- Magage packages using WinGet.
|
|
||||||
options:
|
|
||||||
name:
|
|
||||||
description:
|
|
||||||
- Name of the package to manage.
|
|
||||||
type: str
|
|
||||||
state:
|
|
||||||
description:
|
|
||||||
- Indicates the desired package state. V(latest) ensures that the latest
|
|
||||||
version is installed.
|
|
||||||
type: str
|
|
||||||
choices: [ absent, present, latest ]
|
|
||||||
default: present
|
|
||||||
'''
|
|
||||||
|
|
||||||
EXAMPLES = '''
|
|
||||||
- name: Install Apple Music
|
|
||||||
win_winget:
|
|
||||||
name: Apple Music
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Install latest version of Neovim Qt
|
|
||||||
win_winget:
|
|
||||||
name: neovim-qt
|
|
||||||
state: latest
|
|
||||||
|
|
||||||
- name: Uninstall Microsoft OneDrive
|
|
||||||
win_winget:
|
|
||||||
id: Microsoft.OneDrive
|
|
||||||
state: absent
|
|
||||||
'''
|
|
||||||
|
|
||||||
RETURN = '''
|
|
||||||
stdout:
|
|
||||||
description: Output from WinGet.
|
|
||||||
returned: Success, when needed.
|
|
||||||
type: str
|
|
||||||
sample: ''
|
|
||||||
'''
|
|
@ -6,7 +6,7 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: 1password
|
- role: 1password
|
||||||
- role: autohotkey
|
- role: autohotkey
|
||||||
- role: apple-music
|
- role: cider
|
||||||
- role: ferdium
|
- role: ferdium
|
||||||
- role: firefox
|
- role: firefox
|
||||||
- role: fonts
|
- role: fonts
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: install Apple Music from Microsoft Store
|
- name: install Apple Music from Microsoft Store
|
||||||
win_winget:
|
win_winget:
|
||||||
name: Apple Music
|
id: 9PFHDD62MXS1
|
||||||
state: latest
|
state: latest
|
||||||
|
|
||||||
- name: remove Cider from Chocolatey
|
|
||||||
win_chocolatey:
|
|
||||||
name: Cider
|
|
||||||
state: absent
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
when: ansible_os_family == 'Windows'
|
when: ansible_os_family == 'Windows'
|
||||||
win_chocolatey:
|
win_chocolatey:
|
||||||
name: Cider
|
name: Cider
|
||||||
state: latest
|
state: absent
|
||||||
|
|
||||||
- name: install flatpak package
|
- name: install flatpak package
|
||||||
when: ansible_os_family != 'Windows'
|
when: ansible_os_family != 'Windows'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user