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.6.0).
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 |
---|---|
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:
|
|
whether to use the user defined by ansible_become_user. Choices:
Configuration:
|
|
WSL distribution user Default: Configuration:
|
|
Automatically add host keys to Choices:
Configuration:
|
|
Set this to Choices:
Configuration:
|
|
Number of seconds until the plugin gives up on trying to write a lock file when writing SSH known host keys. Default: Configuration:
|
|
Set to Choices:
Configuration:
|
|
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:
|
|
Remote port to connect to. Default: Configuration:
|
|
Path to private key file to use for authentication. Configuration:
|
|
Proxy information for running the connection via a jumphost. This option is supported by paramiko version 1.9.0 or newer. Default: Configuration:
|
|
Save the host keys to a file. Choices:
Configuration:
|
|
Address of the remote target. Default: Configuration:
|
|
User to login/authenticate as. Can be set from the CLI via the Configuration:
|
|
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:
|
|
Toggles the use of persistence for connections. Choices:
Configuration:
|
|
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:
|
|
Path to the user known hosts file. Used to verify the ssh hosts keys. Default: Configuration:
|
|
WSL distribution name Configuration:
|
|
WSL distribution user Configuration:
|
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