community.general.wsl connection – Run tasks in WSL distribution using wsl.exe CLI via SSH
Note
This connection plugin is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this connection plugin, see Requirements for details.
To use it in a playbook, specify: community.general.wsl.
New in community.general 10.6.0
Synopsis
- Run commands or put/fetch files to an existing WSL distribution using wsl.exe CLI via SSH.
- Uses the Python SSH implementation (Paramiko) to connect to the WSL host.
Requirements
The below requirements are needed on the local controller node that executes this connection.
- paramiko
Parameters
Parameter | Comments |
|---|---|
banner_timeout float | Configures, in seconds, the amount of time to wait for the SSH banner to be presented. This option is supported by paramiko version 1.15.0 or newer. Default: Configuration:
|
become boolean | whether to use the user defined by ansible_become_user. Choices:
Configuration:
|
become_user string | WSL distribution user Default: Configuration:
|
host_key_auto_add boolean | Automatically add host keys to Choices:
Configuration:
|
host_key_checking boolean | Set this to Choices:
Configuration:
|
lock_file_timeout integer | Number of seconds until the plugin gives up on trying to write a lock file when writing SSH known host keys. Default: Configuration:
|
look_for_keys boolean | Set to Choices:
Configuration:
|
password string | Secret used to either login the SSH server or as a passphrase for SSH keys that require it. Can be set from the CLI via the Configuration:
|
port integer | Remote port to connect to. Default: Configuration:
|
private_key_file path | Path to private key file to use for authentication. Configuration:
|
proxy_command string | Proxy information for running the connection via a jumphost. This option is supported by paramiko version 1.9.0 or newer. Default: Configuration:
|
record_host_keys boolean | Save the host keys to a file. Choices:
Configuration:
|
remote_addr string | Address of the remote target. Default: Configuration:
|
remote_user string | User to login/authenticate as. Can be set from the CLI via the Configuration:
|
timeout integer | Number of seconds until the plugin gives up on failing to establish a TCP connection. This option is supported by paramiko version 2.2.0 or newer. Default: Configuration:
|
use_persistent_connections boolean | Toggles the use of persistence for connections. Choices:
Configuration:
|
use_rsa_sha2_algorithms boolean | Whether or not to enable RSA SHA2 algorithms for pubkeys and hostkeys. On paramiko versions older than 2.9, this only affects hostkeys. For behavior matching paramiko<2.9 set this to Choices:
Configuration:
|
user_known_hosts_file path | Path to the user known hosts file. Used to verify the ssh hosts keys. Default: Configuration:
|
wsl_distribution string / required | WSL distribution name Configuration:
|
wsl_user string | WSL distribution user Configuration:
|
Note
Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).
Examples
# ------------------------
# Inventory: inventory.yml
# ------------------------
---
all:
children:
wsl:
hosts:
example-wsl-ubuntu:
ansible_host: 10.0.0.10
wsl_distribution: ubuntu
wsl_user: ubuntu
vars:
ansible_connection: community.general.wsl
ansible_user: vagrant
# ----------------------
# Playbook: playbook.yml
# ----------------------
---
- name: WSL Example
hosts: wsl
gather_facts: true
become: true
tasks:
- name: Ping
ansible.builtin.ping:
- name: Id (with become false)
become: false
changed_when: false
args:
executable: /bin/bash
ansible.builtin.shell: |
exec 2>&1
set -x
echo "$0"
pwd
id
- name: Id (with become true)
changed_when: false
args:
executable: /bin/bash
ansible.builtin.shell: |
exec 2>&1
set -x
echo "$0"
pwd
id
- name: Reboot
ansible.builtin.reboot:
boot_time_command: systemctl show -p ActiveEnterTimestamp init.scope
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/wsl_connection.html