choco source add
command to add the repository, using --user
and --password
arguments to specify the login; then Chocolatey Gui will pick up that source because it uses the same config that choco.exe
uses. The other option is to go into the Chocolatey GUI settings, go over to the sources tab, and set the username and password for the repository source that needs it.
choco install PACKAGES -s .
. 2 out of the 3 work fine when invoked using the win_chocolatey module as well. But one is not working.
2021-01-24 23:05:05,944 6084 [INFO ] - Installing orthocad...
2021-01-24 23:05:05,990 6084 [DEBUG] - Running Start-ChocolateyProcessAsAdmin -validExitCodes '0' -workingDirectory 'C:\tmp\chocolatey\orthocad\1.0' -statements ' ' -exeToRun 'C:\tmp\chocolatey\orthocad\1.0\iTero_Online_Setup_5.9.1.20.exe'
2021-01-24 23:05:05,990 6084 [DEBUG] - Unable to use current location for Working Directory. Using Cache Location instead.
2021-01-24 23:05:06,005 6084 [DEBUG] - Test-ProcessAdminRights: returning True
2021-01-24 23:05:06,020 6084 [DEBUG] - Elevating permissions and running ["C:\tmp\chocolatey\orthocad\1.0\iTero_Online_Setup_5.9.1.20.exe" ]. This may take a while, depending on the statements.
Elevating permissions and running
. So that at least rules out AHK. Not yet sure why it can't move any further. Other packages install and work just fine with Ansible/chocolatey...
vagrant
and they are in the administrators
group
So there must be some slight difference with out the win_chocolatey module executes the script.. or something with WinRM... maybe I can try it through OpenSSH instead.
WinRM could definitely be the problem, I have heard in the past that it had caused issues with certain packages (especially for autohotkey packages, and packages installing services).
Not sure what the exact problem was though, nor if there ever was a solution for it. Testing using ssl could be something worthwhile for you to test in this case, but not sure if that would really solve the issue. But there is a possibility
I've tried it with
- name: Install Orthodontic apps
win_chocolatey:
name: orthocad
source: C:\coretechonomy\chocolatey\
become: yes
become_user: vagrant
become_flags: logon_type=interactive logon_flags=with_profile
# https://docs.ansible.com/ansible/latest/user_guide/become.html
No luck yet though :(
@etho201 You won't be able to install a package using Ansible with Autohotkey. Autohotkey requires an interactive session which you won't get whether you run become
or not (become
really just allows you to either elevate your session or become another user). This isn't a failure of Chocolatey or Ansible. It's just the way that Ansible works. And Puppet. And PowerShell DSC. And Chef. Packages that require Autohotkey are just not going to work running headlessly (as @thecakeisnaoh said above).
Having said that, you might want to look at win_psexec
(Ansible docs). I haven't used it for this specific scenario, so it may still not work, and you will likely need to have a logged on user for it to work (as it interacts with a user session). You will also have to grab the user session ID to use that session (I can share the code I have for this if this is an option for you). What I will say is I have a playbook that builds my desktop from scratch and some software requires to be run interactively (not using it for Chocolatey installs or Autohotkey though) and this is the way I found to get it to work.
@etho201 This is what I use (I've just cut and pasted it so you can tweak for your scenario):
# The qwinsta tool allows us to get the sessions for the default_user and we can then run the psexec commands in that
# session.
- name: "Get Session Id for '{{ default_user }}'"
win_shell: "qwinsta.exe {{ default_user }}"
register: results
tags:
- always
# grab the session id number from the results above
- set_fact:
default_user_session_id: "{{ results.stdout | regex_search(regexp, multiline=True) | trim }}"
vars:
regexp: '\s+(\d+)\s+'
tags:
- always
{{ default_user }}
is known in my playbook so I can use it here. I'm not sure how you'd interactively logon to a computer if somebody isn't already on there. qwinsta
is actually a really useful little tool and you could amend the regex to grab a user logged on at the console instead.
At the end, default_user_session_id
has the session ID for the logged on user.