I am trying to manage a Windows machine from Ubuntu using Ansible. I am able to successfully transfer my target files, including Docker Compose files, to the Windows machine. However, when I try to start the Docker Compose files via Ansible, I encounter the following error:
error getting credentials - err: exit status 1, out: The specified session does not exist. It may have been closed earlier.
When I manually run the docker compose up -d command on the Windows machine, it works successfully.
Setup:
Ansible Playbook:
Install Docker on the Windows machine
Copy the necessary files Start
the application with Docker Compose
Defaults:
I am connecting to the Windows machine via WinRM.
Docker Desktop is installed on the Windows machine.
I face issues running docker compose via Ansible, but it works when I
run it manually on the Windows machine.
The community.docker collection does not support Windows (see the README: Ansible Galaxy).
I don’t know what’s the current state of running Python modules on Windows (outside of WSL), but all modules in that collection are Python modules. There are no PowerShell / CSharp modules in the collection. My guess is that the error you’re seeing,
basically means that Python modules still don’t work under Windows.
This would indicate that the docker.exe command is trying to access something like the user’s secret store or something else not typically available over a network logon (WinRM/SSH will all produce a network logon). You most likely have a few options to get this working:
Use a auth type that does cred delegation, CredSSP for winrm/psrp, password plaintext auth for ssh
Use become on the task with either the become user being SYSTEM or the same ansible_user/ansible_password
See if the docker.exe compose step has something to avoid trying to access the DPAPI store
Try using command through the local connection plugin
The first two options are ways to pretend to be an interactive user and run commands like it would work locally. Reading online it looks like there’s some setting like "credsStore": "secretservice" that could be the culprit in the docker config file. Maybe removing it or seeing if there are other options might work if you don’t need the credential store.
The last option works but only if the playbook is run through WSL:
- name: run docker compose through localhost
command: docker.exe compose -f redis.yml up -d
delegate_to: localhost
As WSL can execute Windows binaries natively this should work, if it can’t find docker.exe in the Linux PATH env var this may work to spawn a sub shell in Windows that can find docker.exe
- name: run docker compose through localhost
shell: docker.exe compose -f redis.yml up -d
args:
executable: /mnt/c/Windows/System32/cmd.exe
chdir: /mnt/c/...
delegate_to: localhost
Hi,Thank you for all the answers. I found the solution to the problem and ı am using winrm. The problem was solved when I added the values
become=yes
become_user=w10
to my windows host in my inventory.ini file.