Compare commits

..

No commits in common. "5210a451b20c0272deb198a5fa69e3725e37cf38" and "a9aa1bdaafbeefc0c89ce1ef1c45dbae7487f62c" have entirely different histories.

4 changed files with 76 additions and 57 deletions

View File

@ -6,9 +6,8 @@
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{
options = @{ options = @{
name = @{ name = @{
type = "list" type = "str"
elements = "str" default = $null
required = $true
} }
state = @{ state = @{
type = "str" type = "str"
@ -19,7 +18,7 @@ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{
supports_check_mode = $false supports_check_mode = $false
}) })
$names = $module.Params.name $name = $module.Params.name
$state = $module.Params.state $state = $module.Params.state
$winget = Get-ExecutablePath "winget" $winget = Get-ExecutablePath "winget"
$noPackageString = "No installed package found matching input criteria." $noPackageString = "No installed package found matching input criteria."
@ -49,48 +48,46 @@ function Test-UpgradeAvailable {
return $true return $true
} }
foreach ($name in $names) { switch ($state) {
switch ($state) { "absent" {
"absent" { if (Test-Installed) {
if (Test-Installed) { $command = "`"$winget`" uninstall `"$name`""
$command = "`"$winget`" uninstall `"$name`"" $result = Run-Command -command $command
$result = Run-Command -command $command if ($result.rc -ne 0) {
if ($result.rc -ne 0) { $module.Result.rc = $result.rc
$module.Result.rc = $result.rc
$module.Result.stdout = $result.stdout
$module.FailJson("Failed to uninstall package `"$name`"")
}
$module.Result.stdout = $result.stdout $module.Result.stdout = $result.stdout
$module.Result.changed = $true $module.FailJson("Failed to uninstall package `"$name`"")
} }
$module.Result.stdout = $result.stdout
$module.Result.changed = $true
} }
}
"latest" { "latest" {
if (Test-UpgradeAvailable) { if (Test-UpgradeAvailable) {
$command = "`"$winget`" install `"$name`"" $command = "`"$winget`" install `"$name`""
$result = Run-Command -command $command $result = Run-Command -command $command
if ($result.rc -ne 0) { if ($result.rc -ne 0) {
$module.Result.rc = $result.rc $module.Result.rc = $result.rc
$module.Result.stdout = $result.stdout
$module.FailJson("Failed to install package `"$name`"")
}
$module.Result.stdout = $result.stdout $module.Result.stdout = $result.stdout
$module.Result.changed = $true $module.FailJson("Failed to install package `"$name`"")
} }
$module.Result.stdout = $result.stdout
$module.Result.changed = $true
} }
}
"present" { "present" {
if (!(Test-Installed)) { if (!(Test-Installed)) {
$command = "`"$winget`" install `"$name`"" $command = "`"$winget`" install `"$name`""
$result = Run-Command -command $command $result = Run-Command -command $command
if ($result.rc -ne 0) { if ($result.rc -ne 0) {
$module.Result.rc = $result.rc $module.Result.rc = $result.rc
$module.Result.stdout = $result.stdout
$module.FailJson("Failed to install package `"$name`"")
}
$module.Result.stdout = $result.stdout $module.Result.stdout = $result.stdout
$module.Result.changed = $true $module.FailJson("Failed to install package `"$name`"")
} }
$module.Result.stdout = $result.stdout
$module.Result.changed = $true
} }
} }
} }

View File

@ -11,7 +11,7 @@ options:
name: name:
description: description:
- Name of the package to manage. - Name of the package to manage.
type: list[str] type: str
state: state:
description: description:
- Indicates the desired package state. V(latest) ensures that the latest - Indicates the desired package state. V(latest) ensures that the latest

View File

@ -1,15 +1,9 @@
--- ---
- name: install winget packages
win_winget:
name:
- neovim.neovim
- equalsraf.neovim-qt
state: latest
- name: remove chocolatey package - name: install chocolatey packages
win_chocolatey: win_chocolatey:
name: neovim name: neovim
state: absent state: latest
- set_fact: - set_fact:
vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim' vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim'
@ -20,15 +14,39 @@
dest: '{{vim_config_dir}}' dest: '{{vim_config_dir}}'
branch: main branch: main
# TODO: Create neovim-qt start menu shortcut # - TODO: neovim install pip packages
# Need a reliable way to get the path to nvim-qt which doesn't reply on # win_pip:
# where.exe or similar as it won't work on first install due to environment # name: '{{neovim_pip_packages}}'
# variable update. winget installs the equalsraf.neovim-qt package in # state: latest
# {{ansible_env.ProgramFiles}}\neovim-qt {{neovim_qt_version}}\bin\nvim.qt.exe
# so if I can get the version out of winget that would be a start. - name: create nvim start menu shortcut
# - name: create nvim start menu shortcut win_shortcut:
# win_shortcut: src: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe'
# src: '{{neovim_qt_exe}}' dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk'
# dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk' icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0'
# icon: '{{neovim_qt_exe}},0' directory: '{{ansible_env.USERPROFILE}}'
# directory: '{{ansible_env.USERPROFILE}}'
- name: check for config repo tasks.yaml
win_stat:
path: '{{vim_config_dir}}/tasks.yaml'
register: config_repo_tasks
# TODO: this doesn't work for non localhost setups
# probably need to copy the tasks.yaml and plugins.yaml to the controller in a
# temporary directory then include them
- when: config_repo_tasks.stat.exists
fetch:
src: '{{vim_config_dir}}/tasks.yaml'
dest: vim_config_tasks.yaml
flat: true
changed_when: false
- when: config_repo_tasks.stat.exists
include_tasks: vim_config_tasks.yaml
- name: remove fetched tasks
file:
state: absent
path: vim_config_tasks.yaml
changed_when: false
delegate_to: localhost

View File

@ -1,3 +1,7 @@
--- ---
neovim_pip_packages: neovim_pip_packages:
- cmake-language-server
- cmakelint
- compdb - compdb
- vim-vint
- yamllint