1. Managed Windows Machine
Ansible 2.8 has added an experimental option to use the SSH connection plugin to manage Windows hosts. To use SSH as the connection to a Windows host, set the following variables in the inventory.
ansible_connection=ssh # Set either cmd or powershell not both. ansible_shell_type=cmd # ansible_shell_type=powershell
The value for ansible_shell_type should either be cmd or powershell. Use cmd if the DefaultShell has not been configured on the SSH service and powershell if that has been set as the DefaultShell.
2. Debian Controller Machine
2.1. Installation
-
Enter the following commands at a Command Line.
sudo apt-get update sudo apt-get install ansible which ansible # /usr/bin/ansible ansible --version # Debian 13.3: 2.19.5 python3 --version # Debian 13.3: Python 3.13.5
2.2. Configuration
-
Enter the following commands at a Command Line.
sudo cp -a /etc/ansible/ansible.cfg /etc/ansible/ansible.cfg.org sudo cp -a /etc/ansible/hosts /etc/ansible/hosts.org scp -p smru@10.10.1.2:/media/Windows/Software/_Delta/id_rsa-auto . chmod 600 id_rsa-auto diff /etc/ansible/ansible.cfg.org /etc/ansible/ansible.cfg71c71 < #host_key_checking = False --- > host_key_checking = False 136c136 < #private_key_file = /path/to/file --- > private_key_file = /home/delta/id_rsa-auto
-
Append the following line sto the /etc/ansible/hosts file.
[linux] #tbhf-tst-mrm 10.10.1.8 [linux:vars] ansible_user=root ansible_password=<level 1 password> [windows] #TBHFWS-IT01 #TBHFWS-IT02 #SMRUWS-IT11 10.10.1.108 10.10.1.77 10.10.1.116 [windows:vars] ansible_connection=ssh ansible_shell_type=cmd ansible_user=Administrator #ansible_password=******** #remote_tmp = %TEMP%
-
Enter the following commands at a Command Line.
ansible --version # 2.19.5 cd ~/Ansible cat ansible.cfg cat inventory.ini
3. Usage
-
Enter the following commands at a Command Line.
ansible linux -m ping ansible linux -u smru -K -m command -a 'id -a' ansible linux -u smru -K -m command -a 'uname -a' ansible windows -m win_ping ansible windows -m raw -a 'msg * Merry Christmas from Douwe.'
4. Inventory.ini
host1 ansible_host=127.0.0.1 ansible_user=vagrant ansible_port=2222 ansible_ssh_private_key_file=./.vagrant/machines/host1/virtualbox/private_key
5. Snel.com
2026-01-05 19:32:23 delta@HOMENB-FRL01 ~/ansible$ ssh-copy-id team@vps-web.deltasoftware.frl
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/delta/.ssh/id_ed25519.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
team@vps-web.deltasoftware.frl's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'team@vps-web.deltasoftware.frl'"
and check to make sure that only the key(s) you wanted were added.
ssh-copy-id delta@localhost
2026-01-05 19:48:38 delta@HOMENB-FRL01 ~/ansible$ cat hosts.ini # See https://blog.hosteons.com/2025/07/22/use-ansible-to-manage-multiple-vps-instances-efficiently/ [webservers] #vps1 ansible_host=192.0.2.1 ansible_user=root vps-web.deltasoftware.frl ansible_host=185.62.58.28 ansible_user=team
2026-01-05 19:50:58 delta@HOMENB-FRL01 ~/ansible$ cat ansible.cfg [defaults] #host_key_checking = False interpreter_python = /usr/bin/python3.11 inventory = ./hosts.ini remote_user = ansible_user [privilege_escalation] become_ask_pass = True
ansible -i hosts.ini all -m ping
vps-web.deltasoftware.frl | SUCCESS => {
"changed": false,
"ping": "pong"
}
ansible -i hosts.ini all -m command -a "ls -al"
ansible -i hosts.ini all -m command -a "ls -al /root"
ansible -i hosts.ini all --ask-become-pass --become -m command -a "sudo ls -al /root"
ansible -i hosts.ini all --become -m command -a "sudo ls -al /root"
ansible-inventory -i hosts.ini --list
-
See https://www.digitalocean.com/community/tutorials/how-to-use-vault-to-protect-sensitive-ansible-data.
-
See https://docs.ansible.com/projects/ansible/latest/os_guide/windows_ssh.html#windows-ssh.
-
See https://www.cherryservers.com/blog/how-to-run-remote-commands-with-ansible-shell-module.
ansible-playbook -i inventory-localhost.ini playbook.yml ansible-playbook -i inventory-localhost.ini bash/playbook.yml ansible-playbook --ask-become-pass --inventory inventory.ini bash/playbook.yml
6. Latest
-
Note: Make sure the default shell of OpenSSH server on the remote computer is set to the default Command Prompt.
reg.exe query HKLM\SOFTWARE\OpenSSH /v DefaultShell reg.exe delete HKLM\SOFTWARE\OpenSSH /v DefaultShell /f reg.exe add HKLM\SOFTWARE\OpenSSH /v DefaultShell /t REG_SZ /d C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe /fDefaultShell REG_SZ C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
6.1. Linux
ansible vps -m ping
ansible wsl_admin -m ping
ansible wsl_douwe -m ping
ansible-playbook --ask-become-pass linux/bash/playbook.yml
ansible-playbook --ask-become-pass linux/facts/playbook.yml
6.2. Windows
setup module - Gathers facts about remote hosts win_command module - Executes a command on a remote Windows node win_ping module - A windows version of the classic ping module win_powershell module - Run PowerShell scripts win_regedit module - Add, change, or remove registry keys and values win_shell module - Execute shell commands on target hosts win_user_profile module - Manages the Windows user profiles.
+
ansible windows -m win_ping
ansible-playbook windows/facts/playbook.yml
ansible-playbook windows/putty/playbook.yml