pyinfra.connectors.winrm module¶
Warning
This connector is in alpha and may change in future releases.
Some Windows facts and Windows operations work but this is to be considered
experimental. For now, only winrm_username
and winrm_password
is
being used. There are other methods for authentication, but they have not yet
been added/experimented with.
The @winrm
connector can be used to communicate with Windows instances that have WinRM enabled.
Examples using @winrm
:
# Get the windows_home fact
pyinfra @winrm/192.168.3.232 --winrm-username vagrant \
--winrm-password vagrant --winrm-port 5985 -vv --debug fact windows_home
# Create a directory
pyinfra @winrm/192.168.3.232 --winrm-username vagrant \
--winrm-password vagrant --winrm-port 5985 windows_files.windows_directory 'c: emp'
# Run a powershell command ('ps' is the default shell-executable for the winrm connector)
pyinfra @winrm/192.168.3.232 --winrm-username vagrant \
--winrm-password vagrant --winrm-port 5985 exec -- write-host hello
# Run a command using the command prompt:
pyinfra @winrm/192.168.3.232 --winrm-username vagrant \
--winrm-password vagrant --winrm-port 5985 --shell-executable cmd exec -- date /T
# Run a command using the winrm ntlm transport
pyinfra @winrm/192.168.3.232 --winrm-username vagrant \
--winrm-password vagrant --winrm-port 5985 --winrm-transport ntlm exec -- hostname
-
class
pyinfra.connectors.winrm.
Meta
¶ Bases:
BaseConnectorMeta
-
class
DataKeys
¶ Bases:
object
-
hostname
= 'WinRM hostname to connect to'¶
-
operation_timeout_sec
= 'Operation timeout in seconds (default: ``20``)'¶
-
password
= 'WinRM password'¶
-
port
= 'WinRM port to connect to'¶
-
read_timeout_sec
= 'Read timeout in seconds (default: ``30``)'¶
-
transport
= 'WinRM transport (default: ``plaintext``)'¶
-
user
= 'WinRM username'¶
-
-
handles_execution
= True¶
-
keys_prefix
= 'winrm'¶
-
class
-
pyinfra.connectors.winrm.
connect
(state, host)¶ Connect to a single host. Returns the winrm Session if successful.
-
pyinfra.connectors.winrm.
get_file
(state, host, remote_filename, filename_or_io, remote_temp_filename=None, **command_kwargs)¶
-
pyinfra.connectors.winrm.
make_names_data
(hostname)¶
-
pyinfra.connectors.winrm.
put_file
(state, host, filename_or_io, remote_filename, print_output=False, print_input=False, remote_temp_filename=None, **command_kwargs)¶ Upload file by chunking and sending base64 encoded via winrm
-
pyinfra.connectors.winrm.
run_shell_command
(state, host, command, env=None, success_exit_codes=None, print_output=False, print_input=False, return_combined_output=False, shell_executable=None, **ignored_command_kwargs)¶ Execute a command on the specified host.
- Parameters
- state (
pyinfra.api.State
obj) – state object for this command - hostname (string) – hostname of the target
- command (string) – actual command to execute
- success_exit_codes (list) – all values in the list that will return success
- print_output (boolean) – print the output
- print_intput (boolean) – print the input
- return_combined_output (boolean) – combine the stdout and stderr lists
- shell_executable (string) – shell to use - ‘cmd’=cmd, ‘ps’=powershell(default)
- env (dict) – environment variables to set
- state (
- Returns
(exit_code, stdout, stderr) stdout and stderr are both lists of strings from each buffer.
- Return type
tuple
-
pyinfra.connectors.winrm.
show_warning
()¶