Open gcc42 opened 1 year ago
I have also encountered this issue in our development environment (still working fine in the production environment).
ansible-playbook [core 2.13.3]
config file = /runner/project/ansible.cfg
configured module search path = ['/runner/project/library']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /runner/requirements_collections:/home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.9.7 (default, Sep 13 2021, 08:18:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
jinja version = 3.0.3
libyaml = True
Running this via Ansible Automation Platform
https://github.com/chocolatey/chocolatey-ansible/issues/130#issuecomment-1654243666
Sorted out our issue -- our error was slightly different
Cannot index into a null array.
At line:122 char:17
$chocoCommand = Install-Chocolatey @installParams
Root cause: instead of allowing the win_chocholatey
module to bootstrap chocolatey, we wrote a separate poweshell script (much easier to read -- but also because we don't have to deal with older OSes or versions of Powershell) that intalls chocolatey from our own internal repository -- in any event, while chocolatey is installed without incident, it does not actually appear as an installed package. In reviewing the modules code, it looks as if even though the choco binary is present, the fact that its not listed as an installed package leaves all of the expected parameters as undefined.
My quick solution was to simply add a win_powershell
task that runs choco.exe install chocolatey --exact --skip-powershell --yes
that adds the package without performing additional steps.
We are also experiencing this.
However, running ansible as become_user
does not seem to change anything.
Even after my work arounds, I keep coming back to this line (albeit a slightly different version of the module).
My question - why are we "installing" chocolatey right out of the gate with this module instead of just checking to see if its present? Am I misreading how this module works?
Install-Chocolatey defined: https://github.com/chocolatey/chocolatey-ansible/blob/9bdc0d40437a7dc7f0181af42da7e35bbcfcae4a/chocolatey/plugins/module_utils/Packages.psm1#L1018
Why are we "installing" chocolatey right out of the gate with this module instead of just checking to see if its present?
By my read, the first few lines of Install-Chocolatey
are a test to see if the command is present and skip install if it is found. The function, overall, is almost a wrapper for Get-ChocolateyCommand
(which does check if it's already present) - but with logic to ensure Chocolatey is present (and/or a greater version than 0.10.5) if not found initially.
$chocoCommand = Get-ChocolateyCommand -IgnoreMissing
if ($null -eq $chocoCommand) {
# We need to install chocolatey
# ...
}
# ...
$chocoCommand
the fact that its not listed as an installed package leaves all of the expected parameters as undefined.
Root cause: instead of allowing the win_chocholatey module to bootstrap chocolatey, we wrote a separate poweshell script (much easier to read
FWIW, though I've not seen the script you're using, if you end it by copying the Chocolatey nupkg you used to install into the correct folder within the /lib/
directory (as we do at the end of the standard install.ps1
) that should solve this. I agree that this is a fun behavioural quirk / workaround.
Write-Host 'Ensuring chocolatey.nupkg is in the lib folder'
$chocoPkgDir = Join-Path $chocoPath -ChildPath 'lib\chocolatey'
$nupkg = Join-Path $chocoPkgDir -ChildPath 'chocolatey.nupkg'
The error encountered here actually looks identical to the one from #147, I wonder if these two issues are related in some way.
Checklist
What You Are Seeing?
This is on WSL on Windows, an initial install worked as expected, now I did something (possibly upgrade powershell to v5?) which broke win_chocolatey and other chocolatey modules completely. Note that
choco install vlc
for example on windows still succeeds. I see the same error on, for example,win_chocolatey_facts
.or
Inventory just links to the same windows host running WinRM. The above command gives me:
However, if I
become_user
system, it seems to fix the issue:outputs:
Either the error message in the first case is highly misleading, or something else fixes the issue when becoming system.
What is Expected?
Expecting the packages to be successfully installed.
How Did You Get This To Happen?
python3 -m pip install ansible && python3 -m pip install --upgrade ansible
win_ping
module works, butwin_chocolatey
,win_chocolatey_facts
etc. shows with the error aboveSystem Details
Installed Packages
Output Log
Additional Context
I tried this for various packages, like notepadplusplus, vlc, filezilla, nirlauncher and same issue. Like I mentioned, I did something that broke a previously working win_chocolatey.
Running Ansible on WSL (Windows Subsystem for Linux) on Windows.