ansible.plugins.connection package

ansible.plugins.connection.ensure_connect(func)[source]
class ansible.plugins.connection.ConnectionBase(play_context, new_stdin, *args, **kwargs)[source]

Bases: object

A base class for connections to contain common code.

has_pipelining = False
become_methods = ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'doas', 'dzdo']
module_implementation_preferences = ('',)
allow_executable = True
connected

Read-only property holding whether the connection to the remote host is active or closed.

set_host_overrides(host, hostvars=None)[source]

An optional method, which can be used to set connection plugin parameters from variables set on the host (or groups to which the host belongs)

Any connection plugin using this should first initialize its attributes in an overridden def __init__(self):, and then use host.get_vars() to find variables which may be used to set those attributes in this method.

transport

String used to identify this Connection class from other classes

exec_command(*args, **kwargs)[source]

Run a command on the remote host.

Parameters:
  • cmd (bytestring) – byte string containing the command
  • in_data – If set, this data is passed to the command’s stdin. This is used to implement pipelining. Currently not all connection plugins implement pipelining.
  • sudoable – Tell the connection plugin if we’re executing a command via a privilege escalation mechanism. This may affect how the connection plugin returns data. Note that not all connections can handle privilege escalation.
Returns:

a tuple of (return code, stdout, stderr) The return code is an int while stdout and stderr are both byte strings.

When a command is executed, it goes through multiple commands to get there. It looks approximately like this:

[LocalShell] ConnectionCommand [UsersLoginShell (*)] ANSIBLE_SHELL_EXECUTABLE [(BecomeCommand ANSIBLE_SHELL_EXECUTABLE)] Command
LocalShell:Is optional. It is run locally to invoke the Connection Command. In most instances, the ConnectionCommand can be invoked directly instead. The ssh connection plugin which can have values that need expanding locally specified via ssh_args is the sole known exception to this. Shell metacharacters in the command itself should be processed on the remote machine, not on the local machine so no shell is needed on the local machine. (Example, /bin/sh)
ConnectionCommand:
 This is the command that connects us to the remote machine to run the rest of the command. ansible_ssh_user, ansible_ssh_host and so forth are fed to this piece of the command to connect to the correct host (Examples ssh, chroot)
UsersLoginShell:
 This shell may or may not be created depending on the ConnectionCommand used by the connection plugin. This is the shell that the ansible_ssh_user has configured as their login shell. In traditional UNIX parlance, this is the last field of a user’s /etc/passwd entry We do not specifically try to run the UsersLoginShell when we connect. Instead it is implicit in the actions that the ConnectionCommand takes when it connects to a remote machine. ansible_shell_type may be set to inform ansible of differences in how the UsersLoginShell handles things like quoting if a shell has different semantics than the Bourne shell.
ANSIBLE_SHELL_EXECUTABLE:
 This is the shell set via the inventory var ansible_shell_executable or via constants.DEFAULT_EXECUTABLE if the inventory var is not set. We explicitly invoke this shell so that we have predictable quoting rules at this point. ANSIBLE_SHELL_EXECUTABLE is only settable by the user because some sudo setups may only allow invoking a specific shell. (For instance, /bin/bash may be allowed but /bin/sh, our default, may not). We invoke this twice, once after the ConnectionCommand and once after the BecomeCommand. After the ConnectionCommand, this is run by the UsersLoginShell. After the BecomeCommand we specify that the ANSIBLE_SHELL_EXECUTABLE is being invoked directly.
BecomeComand ANSIBLE_SHELL_EXECUTABLE:
 Is the command that performs privilege escalation. Setting this up is performed by the action plugin prior to running exec_command. So we just get passed :param cmd which has the BecomeCommand already added. (Examples: sudo, su) If we have a BecomeCommand then we will invoke a ANSIBLE_SHELL_EXECUTABLE shell inside of it so that we have a consistent view of quoting.
Command:Is the command we’re actually trying to run remotely. (Examples: mkdir -p $HOME/.ansible, python $HOME/.ansible/tmp-script-file)
put_file(*args, **kwargs)[source]

Transfer a file from local to remote

fetch_file(*args, **kwargs)[source]

Fetch a file from remote to local

close()[source]

Terminate the connection

check_become_success(output)[source]
check_password_prompt(output)[source]
check_incorrect_password(output)[source]
check_missing_password(output)[source]
connection_lock()[source]
connection_unlock()[source]

Submodules

ansible.plugins.connection.accelerate module

class ansible.plugins.connection.accelerate.Connection(*args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

raw socket accelerated connection

transport = 'accelerate'
has_pipelining = False
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'sudo', 'su', 'doas'])
send_data(data)[source]
recv_data()[source]
validate_user()[source]

Checks the remote uid of the accelerated daemon vs. the one specified for this play and will cause the accel daemon to exit if they don’t match

exec_command(cmd, in_data=None, sudoable=True)[source]

run a command on the remote host

put_file(in_path, out_path)[source]

transfer a file from local to remote

fetch_file(in_path, out_path)[source]

save a remote file to the specified path

close()[source]

terminate the connection

ansible.plugins.connection.chroot module

class ansible.plugins.connection.chroot.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local chroot based connections

transport = 'chroot'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'runas', 'sudo', 'doas'])
exec_command(cmd, in_data=None, sudoable=False)[source]

run a command on the chroot

put_file(in_path, out_path)[source]

transfer a file from local to chroot

fetch_file(in_path, out_path)[source]

fetch a file from chroot to local

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.docker module

class ansible.plugins.connection.docker.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local docker based connections

transport = 'docker'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'runas', 'sudo', 'doas'])
exec_command(cmd, in_data=None, sudoable=False)[source]

Run a command on the docker host

put_file(in_path, out_path)[source]

Transfer a file from local to docker container

fetch_file(in_path, out_path)[source]

Fetch a file from container to local.

close()[source]

Terminate the connection. Nothing to do for Docker

ansible.plugins.connection.funcd module

class ansible.plugins.connection.funcd.Connection(runner, host, port, *args, **kwargs)[source]

Bases: object

Func-based connections

connect(port=None)[source]
exec_command(cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None)[source]

run a command on the remote minion

put_file(in_path, out_path)[source]

transfer a file from local to remote

fetch_file(in_path, out_path)[source]

fetch a file from remote to local

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.jail module

class ansible.plugins.connection.jail.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local BSD Jail based connections

transport = 'jail'
has_pipelining = True
become_methods = frozenset([])
list_jails()[source]
get_jail_path()[source]
exec_command(cmd, in_data=None, sudoable=False)[source]

run a command on the jail

put_file(in_path, out_path)[source]

transfer a file from local to jail

fetch_file(in_path, out_path)[source]

fetch a file from jail to local

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.libvirt_lxc module

class ansible.plugins.connection.libvirt_lxc.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local lxc based connections

transport = 'libvirt_lxc'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'runas', 'sudo', 'doas'])
exec_command(cmd, in_data=None, sudoable=False)[source]

run a command on the chroot

put_file(in_path, out_path)[source]

transfer a file from local to lxc

fetch_file(in_path, out_path)[source]

fetch a file from lxc to local

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.local module

class ansible.plugins.connection.local.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local based connections

transport = 'local'
has_pipelining = True
exec_command(cmd, in_data=None, sudoable=True)[source]

run a command on the local host

put_file(in_path, out_path)[source]

transfer a file from local to local

fetch_file(in_path, out_path)[source]

fetch a file from local to local – for copatibility

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.lxc module

class ansible.plugins.connection.lxc.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local lxc based connections

transport = 'lxc'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'runas', 'sudo', 'su', 'doas', 'dzdo'])
exec_command(cmd, in_data=None, sudoable=False)[source]

run a command on the chroot

put_file(in_path, out_path)[source]

transfer a file from local to lxc

fetch_file(in_path, out_path)[source]

fetch a file from lxc to local

close()[source]

terminate the connection; nothing to do here

ansible.plugins.connection.lxd module

class ansible.plugins.connection.lxd.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

lxd based connections

transport = 'lxd'
has_pipelining = True
exec_command(cmd, in_data=None, sudoable=True)[source]

execute a command on the lxd host

put_file(in_path, out_path)[source]

put a file from local to lxd

fetch_file(in_path, out_path)[source]

fetch a file from lxd to local

close()[source]

close the connection (nothing to do here)

ansible.plugins.connection.paramiko_ssh module

class ansible.plugins.connection.paramiko_ssh.MyAddPolicy(new_stdin, connection)[source]

Bases: object

Based on AutoAddPolicy in paramiko so we can determine when keys are added and also prompt for input.

Policy for automatically adding the hostname and new host key to the local L{HostKeys} object, and saving it. This is used by L{SSHClient}.

missing_host_key(client, hostname, key)[source]
class ansible.plugins.connection.paramiko_ssh.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

SSH based connections with Paramiko

transport = 'paramiko'
exec_command(cmd, in_data=None, sudoable=True)[source]

run a command on the remote host

put_file(in_path, out_path)[source]

transfer a file from local to remote

fetch_file(in_path, out_path)[source]

save a remote file to the specified path

close()[source]

terminate the connection

ansible.plugins.connection.ssh module

class ansible.plugins.connection.ssh.Connection(*args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

ssh based connections

transport = 'ssh'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'sudo', 'su', 'doas'])
exec_command(*args, **kwargs)[source]

Wrapper around _exec_command to retry in the case of an ssh failure

Will retry if: * an exception is caught * ssh returns 255 Will not retry if * remaining_tries is <2 * retries limit reached

put_file(in_path, out_path)[source]

transfer a file from local to remote

fetch_file(in_path, out_path)[source]

fetch a file from remote to local

close()[source]

ansible.plugins.connection.winrm module

ansible.plugins.connection.zone module

class ansible.plugins.connection.zone.Connection(play_context, new_stdin, *args, **kwargs)[source]

Bases: ansible.plugins.connection.ConnectionBase

Local zone based connections

transport = 'zone'
has_pipelining = True
become_methods = frozenset(['pbrun', 'pfexec', 'dzdo', 'runas', 'sudo', 'doas'])
list_zones()[source]
get_zone_path()[source]
exec_command(cmd, in_data=None, sudoable=False)[source]

run a command on the zone

put_file(in_path, out_path)[source]

transfer a file from local to zone

fetch_file(in_path, out_path)[source]

fetch a file from zone to local

close()[source]

terminate the connection; nothing to do here