[Ansible Galaxy] Use Ansible with Paramiko

Paramiko

Paramiko is a pure-Python (2.7, 3.4+) implementation of the SSHv2 protocol, providing both client and server functionality. It provides the foundation for the high-level SSH library Fabric, which is what we recommend you use for common client use-cases such as running remote shell commands or transferring files.

Direct use of Paramiko itself is only intended for users who need advanced/low-level primitives or want to run an in-Python sshd.

Installation

The recommended way to get Paramiko is to install the latest stable release via pip:

1
$ pip install paramiko

Usages

First, create or edit a hosts.ini inventory file.

1
2
3
4
5
6
7
# hosts.ini

[your_host]
your_host1 ansible_password=<Your Password>

# [your_host:vars]
# ansible_password=<Your Password>

Use -c paramiko options to specify paramiko.

1
$ ansible-playbook -i hosts.ini -c paramiko myplaybook.yml

Or provide password argument with --ask-pass options.

1
2
$ ansible-playbook -i hosts.ini -c paramiko --ask-pass myplaybook.yml
SSH password:

References

[1] Welcome to Paramiko! — Paramiko documentation - https://www.paramiko.org/

[2] ansible.builtin.paramiko_ssh – Run tasks via python ssh (paramiko) — Ansible Documentation - https://docs.ansible.com/ansible/latest/collections/ansible/builtin/paramiko_ssh_connection.html

[3] paramiko/paramiko: The leading native Python SSHv2 protocol library. - https://github.com/paramiko/paramiko