Merge branch 'me_rmpyvenv' of mdn/ansible into master
This commit is contained in:
247
bin/Activate.ps1
247
bin/Activate.ps1
@@ -1,247 +0,0 @@
|
|||||||
<#
|
|
||||||
.Synopsis
|
|
||||||
Activate a Python virtual environment for the current PowerShell session.
|
|
||||||
|
|
||||||
.Description
|
|
||||||
Pushes the python executable for a virtual environment to the front of the
|
|
||||||
$Env:PATH environment variable and sets the prompt to signify that you are
|
|
||||||
in a Python virtual environment. Makes use of the command line switches as
|
|
||||||
well as the `pyvenv.cfg` file values present in the virtual environment.
|
|
||||||
|
|
||||||
.Parameter VenvDir
|
|
||||||
Path to the directory that contains the virtual environment to activate. The
|
|
||||||
default value for this is the parent of the directory that the Activate.ps1
|
|
||||||
script is located within.
|
|
||||||
|
|
||||||
.Parameter Prompt
|
|
||||||
The prompt prefix to display when this virtual environment is activated. By
|
|
||||||
default, this prompt is the name of the virtual environment folder (VenvDir)
|
|
||||||
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -Verbose
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
|
||||||
and shows extra information about the activation as it executes.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
|
||||||
Activates the Python virtual environment located in the specified location.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -Prompt "MyPython"
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
|
||||||
and prefixes the current prompt with the specified string (surrounded in
|
|
||||||
parentheses) while the virtual environment is active.
|
|
||||||
|
|
||||||
.Notes
|
|
||||||
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
|
||||||
execution policy for the user. You can do this by issuing the following PowerShell
|
|
||||||
command:
|
|
||||||
|
|
||||||
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
|
||||||
|
|
||||||
For more information on Execution Policies:
|
|
||||||
https://go.microsoft.com/fwlink/?LinkID=135170
|
|
||||||
|
|
||||||
#>
|
|
||||||
Param(
|
|
||||||
[Parameter(Mandatory = $false)]
|
|
||||||
[String]
|
|
||||||
$VenvDir,
|
|
||||||
[Parameter(Mandatory = $false)]
|
|
||||||
[String]
|
|
||||||
$Prompt
|
|
||||||
)
|
|
||||||
|
|
||||||
<# Function declarations --------------------------------------------------- #>
|
|
||||||
|
|
||||||
<#
|
|
||||||
.Synopsis
|
|
||||||
Remove all shell session elements added by the Activate script, including the
|
|
||||||
addition of the virtual environment's Python executable from the beginning of
|
|
||||||
the PATH variable.
|
|
||||||
|
|
||||||
.Parameter NonDestructive
|
|
||||||
If present, do not remove this function from the global namespace for the
|
|
||||||
session.
|
|
||||||
|
|
||||||
#>
|
|
||||||
function global:deactivate ([switch]$NonDestructive) {
|
|
||||||
# Revert to original values
|
|
||||||
|
|
||||||
# The prior prompt:
|
|
||||||
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
|
||||||
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
|
||||||
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
|
||||||
}
|
|
||||||
|
|
||||||
# The prior PYTHONHOME:
|
|
||||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
|
||||||
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
|
||||||
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
}
|
|
||||||
|
|
||||||
# The prior PATH:
|
|
||||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
|
||||||
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
|
||||||
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove the VIRTUAL_ENV altogether:
|
|
||||||
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
|
||||||
Remove-Item -Path env:VIRTUAL_ENV
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
|
||||||
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
|
||||||
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
|
||||||
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
|
||||||
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
|
||||||
}
|
|
||||||
|
|
||||||
# Leave deactivate function in the global namespace if requested:
|
|
||||||
if (-not $NonDestructive) {
|
|
||||||
Remove-Item -Path function:deactivate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<#
|
|
||||||
.Description
|
|
||||||
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
|
||||||
given folder, and returns them in a map.
|
|
||||||
|
|
||||||
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
|
||||||
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
|
||||||
then it is considered a `key = value` line. The left hand string is the key,
|
|
||||||
the right hand is the value.
|
|
||||||
|
|
||||||
If the value starts with a `'` or a `"` then the first and last character is
|
|
||||||
stripped from the value before being captured.
|
|
||||||
|
|
||||||
.Parameter ConfigDir
|
|
||||||
Path to the directory that contains the `pyvenv.cfg` file.
|
|
||||||
#>
|
|
||||||
function Get-PyVenvConfig(
|
|
||||||
[String]
|
|
||||||
$ConfigDir
|
|
||||||
) {
|
|
||||||
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
|
||||||
|
|
||||||
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
|
||||||
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
|
||||||
|
|
||||||
# An empty map will be returned if no config file is found.
|
|
||||||
$pyvenvConfig = @{ }
|
|
||||||
|
|
||||||
if ($pyvenvConfigPath) {
|
|
||||||
|
|
||||||
Write-Verbose "File exists, parse `key = value` lines"
|
|
||||||
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
|
||||||
|
|
||||||
$pyvenvConfigContent | ForEach-Object {
|
|
||||||
$keyval = $PSItem -split "\s*=\s*", 2
|
|
||||||
if ($keyval[0] -and $keyval[1]) {
|
|
||||||
$val = $keyval[1]
|
|
||||||
|
|
||||||
# Remove extraneous quotations around a string value.
|
|
||||||
if ("'""".Contains($val.Substring(0, 1))) {
|
|
||||||
$val = $val.Substring(1, $val.Length - 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
$pyvenvConfig[$keyval[0]] = $val
|
|
||||||
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $pyvenvConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
<# Begin Activate script --------------------------------------------------- #>
|
|
||||||
|
|
||||||
# Determine the containing directory of this script
|
|
||||||
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
||||||
$VenvExecDir = Get-Item -Path $VenvExecPath
|
|
||||||
|
|
||||||
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
|
||||||
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
|
||||||
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
|
||||||
|
|
||||||
# Set values required in priority: CmdLine, ConfigFile, Default
|
|
||||||
# First, get the location of the virtual environment, it might not be
|
|
||||||
# VenvExecDir if specified on the command line.
|
|
||||||
if ($VenvDir) {
|
|
||||||
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
|
||||||
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
|
||||||
Write-Verbose "VenvDir=$VenvDir"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Next, read the `pyvenv.cfg` file to determine any required value such
|
|
||||||
# as `prompt`.
|
|
||||||
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
|
||||||
|
|
||||||
# Next, set the prompt from the command line, or the config file, or
|
|
||||||
# just use the name of the virtual environment folder.
|
|
||||||
if ($Prompt) {
|
|
||||||
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
|
||||||
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
|
||||||
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
|
||||||
$Prompt = $pyvenvCfg['prompt'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
|
||||||
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
|
||||||
$Prompt = Split-Path -Path $venvDir -Leaf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Verbose "Prompt = '$Prompt'"
|
|
||||||
Write-Verbose "VenvDir='$VenvDir'"
|
|
||||||
|
|
||||||
# Deactivate any currently active virtual environment, but leave the
|
|
||||||
# deactivate function in place.
|
|
||||||
deactivate -nondestructive
|
|
||||||
|
|
||||||
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
|
||||||
# that there is an activated venv.
|
|
||||||
$env:VIRTUAL_ENV = $VenvDir
|
|
||||||
|
|
||||||
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
|
||||||
|
|
||||||
Write-Verbose "Setting prompt to '$Prompt'"
|
|
||||||
|
|
||||||
# Set the prompt to include the env name
|
|
||||||
# Make sure _OLD_VIRTUAL_PROMPT is global
|
|
||||||
function global:_OLD_VIRTUAL_PROMPT { "" }
|
|
||||||
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
|
||||||
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
|
||||||
|
|
||||||
function global:prompt {
|
|
||||||
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
|
||||||
_OLD_VIRTUAL_PROMPT
|
|
||||||
}
|
|
||||||
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clear PYTHONHOME
|
|
||||||
if (Test-Path -Path Env:PYTHONHOME) {
|
|
||||||
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
Remove-Item -Path Env:PYTHONHOME
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add the venv to the PATH
|
|
||||||
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
|
||||||
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
|
||||||
Binary file not shown.
69
bin/activate
69
bin/activate
@@ -1,69 +0,0 @@
|
|||||||
# This file must be used with "source bin/activate" *from bash*
|
|
||||||
# you cannot run it directly
|
|
||||||
|
|
||||||
deactivate () {
|
|
||||||
# reset old environment variables
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
|
||||||
PATH="${_OLD_VIRTUAL_PATH:-}"
|
|
||||||
export PATH
|
|
||||||
unset _OLD_VIRTUAL_PATH
|
|
||||||
fi
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
|
||||||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
|
||||||
export PYTHONHOME
|
|
||||||
unset _OLD_VIRTUAL_PYTHONHOME
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This should detect bash and zsh, which have a hash command that must
|
|
||||||
# be called to get it to forget past commands. Without forgetting
|
|
||||||
# past commands the $PATH changes we made may not be respected
|
|
||||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
|
||||||
hash -r 2> /dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
|
||||||
PS1="${_OLD_VIRTUAL_PS1:-}"
|
|
||||||
export PS1
|
|
||||||
unset _OLD_VIRTUAL_PS1
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset VIRTUAL_ENV
|
|
||||||
unset VIRTUAL_ENV_PROMPT
|
|
||||||
if [ ! "${1:-}" = "nondestructive" ] ; then
|
|
||||||
# Self destruct!
|
|
||||||
unset -f deactivate
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# unset irrelevant variables
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
VIRTUAL_ENV="/opt/ansible"
|
|
||||||
export VIRTUAL_ENV
|
|
||||||
|
|
||||||
_OLD_VIRTUAL_PATH="$PATH"
|
|
||||||
PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
||||||
export PATH
|
|
||||||
|
|
||||||
# unset PYTHONHOME if set
|
|
||||||
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
|
||||||
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
|
||||||
if [ -n "${PYTHONHOME:-}" ] ; then
|
|
||||||
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
|
||||||
unset PYTHONHOME
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
|
||||||
_OLD_VIRTUAL_PS1="${PS1:-}"
|
|
||||||
PS1="(ansible) ${PS1:-}"
|
|
||||||
export PS1
|
|
||||||
VIRTUAL_ENV_PROMPT="(ansible) "
|
|
||||||
export VIRTUAL_ENV_PROMPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This should detect bash and zsh, which have a hash command that must
|
|
||||||
# be called to get it to forget past commands. Without forgetting
|
|
||||||
# past commands the $PATH changes we made may not be respected
|
|
||||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
|
||||||
hash -r 2> /dev/null
|
|
||||||
fi
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# This file must be used with "source bin/activate.csh" *from csh*.
|
|
||||||
# You cannot run it directly.
|
|
||||||
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
|
||||||
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
|
||||||
|
|
||||||
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
|
||||||
|
|
||||||
# Unset irrelevant variables.
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
setenv VIRTUAL_ENV "/opt/ansible"
|
|
||||||
|
|
||||||
set _OLD_VIRTUAL_PATH="$PATH"
|
|
||||||
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
|
|
||||||
|
|
||||||
|
|
||||||
set _OLD_VIRTUAL_PROMPT="$prompt"
|
|
||||||
|
|
||||||
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
|
||||||
set prompt = "(ansible) $prompt"
|
|
||||||
setenv VIRTUAL_ENV_PROMPT "(ansible) "
|
|
||||||
endif
|
|
||||||
|
|
||||||
alias pydoc python -m pydoc
|
|
||||||
|
|
||||||
rehash
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
|
||||||
# (https://fishshell.com/); you cannot run it directly.
|
|
||||||
|
|
||||||
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
|
||||||
# reset old environment variables
|
|
||||||
if test -n "$_OLD_VIRTUAL_PATH"
|
|
||||||
set -gx PATH $_OLD_VIRTUAL_PATH
|
|
||||||
set -e _OLD_VIRTUAL_PATH
|
|
||||||
end
|
|
||||||
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
|
||||||
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
set -e _OLD_VIRTUAL_PYTHONHOME
|
|
||||||
end
|
|
||||||
|
|
||||||
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
|
||||||
functions -e fish_prompt
|
|
||||||
set -e _OLD_FISH_PROMPT_OVERRIDE
|
|
||||||
functions -c _old_fish_prompt fish_prompt
|
|
||||||
functions -e _old_fish_prompt
|
|
||||||
end
|
|
||||||
|
|
||||||
set -e VIRTUAL_ENV
|
|
||||||
set -e VIRTUAL_ENV_PROMPT
|
|
||||||
if test "$argv[1]" != "nondestructive"
|
|
||||||
# Self-destruct!
|
|
||||||
functions -e deactivate
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Unset irrelevant variables.
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
set -gx VIRTUAL_ENV "/opt/ansible"
|
|
||||||
|
|
||||||
set -gx _OLD_VIRTUAL_PATH $PATH
|
|
||||||
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
|
|
||||||
|
|
||||||
# Unset PYTHONHOME if set.
|
|
||||||
if set -q PYTHONHOME
|
|
||||||
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
|
||||||
set -e PYTHONHOME
|
|
||||||
end
|
|
||||||
|
|
||||||
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
|
||||||
# fish uses a function instead of an env var to generate the prompt.
|
|
||||||
|
|
||||||
# Save the current fish_prompt function as the function _old_fish_prompt.
|
|
||||||
functions -c fish_prompt _old_fish_prompt
|
|
||||||
|
|
||||||
# With the original prompt function renamed, we can override with our own.
|
|
||||||
function fish_prompt
|
|
||||||
# Save the return status of the last command.
|
|
||||||
set -l old_status $status
|
|
||||||
|
|
||||||
# Output the venv prompt; color taken from the blue of the Python logo.
|
|
||||||
printf "%s%s%s" (set_color 4B8BBE) "(ansible) " (set_color normal)
|
|
||||||
|
|
||||||
# Restore the return status of the previous command.
|
|
||||||
echo "exit $old_status" | .
|
|
||||||
# Output the original/"old" prompt.
|
|
||||||
_old_fish_prompt
|
|
||||||
end
|
|
||||||
|
|
||||||
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
|
||||||
set -gx VIRTUAL_ENV_PROMPT "(ansible) "
|
|
||||||
end
|
|
||||||
170
bin/ansible
170
bin/ansible
@@ -1,170 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# PYTHON_ARGCOMPLETE_OK
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
import errno
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
# Used for determining if the system is running a new enough python version
|
|
||||||
# and should only restrict on our documented minimum versions
|
|
||||||
_PY38_MIN = sys.version_info[:2] >= (3, 8)
|
|
||||||
if not _PY38_MIN:
|
|
||||||
raise SystemExit(
|
|
||||||
'ERROR: Ansible requires Python 3.8 or newer on the controller. '
|
|
||||||
'Current version: %s' % ''.join(sys.version.splitlines())
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# These lines appear after the PY38 check, to ensure the "friendly" error happens before
|
|
||||||
# any invalid syntax appears in other files that may get imported
|
|
||||||
from ansible import context
|
|
||||||
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
class LastResort(object):
|
|
||||||
# OUTPUT OF LAST RESORT
|
|
||||||
def display(self, msg, log_only=None):
|
|
||||||
print(msg, file=sys.stderr)
|
|
||||||
|
|
||||||
def error(self, msg, wrap_text=None):
|
|
||||||
print(msg, file=sys.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
display = LastResort()
|
|
||||||
|
|
||||||
try: # bad ANSIBLE_CONFIG or config options can force ugly stacktrace
|
|
||||||
import ansible.constants as C
|
|
||||||
from ansible.utils.display import Display, initialize_locale
|
|
||||||
except AnsibleOptionsError as e:
|
|
||||||
display.error(to_text(e), wrap_text=False)
|
|
||||||
sys.exit(5)
|
|
||||||
|
|
||||||
initialize_locale()
|
|
||||||
|
|
||||||
cli = None
|
|
||||||
me = Path(sys.argv[0]).name
|
|
||||||
|
|
||||||
try:
|
|
||||||
display = Display()
|
|
||||||
display.debug("starting run")
|
|
||||||
|
|
||||||
sub = None
|
|
||||||
target = me.split('-')
|
|
||||||
if target[-1][0].isdigit():
|
|
||||||
# Remove any version or python version info as downstreams
|
|
||||||
# sometimes add that
|
|
||||||
target = target[:-1]
|
|
||||||
|
|
||||||
if len(target) > 1:
|
|
||||||
sub = target[1]
|
|
||||||
myclass = "%sCLI" % sub.capitalize()
|
|
||||||
elif target[0] == 'ansible':
|
|
||||||
sub = 'adhoc'
|
|
||||||
myclass = 'AdHocCLI'
|
|
||||||
else:
|
|
||||||
raise AnsibleError("Unknown Ansible alias: %s" % me)
|
|
||||||
|
|
||||||
try:
|
|
||||||
mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
|
|
||||||
except ImportError as e:
|
|
||||||
# ImportError members have changed in py3
|
|
||||||
if 'msg' in dir(e):
|
|
||||||
msg = e.msg
|
|
||||||
else:
|
|
||||||
msg = e.message
|
|
||||||
if msg.endswith(' %s' % sub):
|
|
||||||
raise AnsibleError("Ansible sub-program not implemented: %s" % me)
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
ansible_dir = Path("~/.ansible").expanduser()
|
|
||||||
try:
|
|
||||||
ansible_dir.mkdir(mode=0o700)
|
|
||||||
except OSError as exc:
|
|
||||||
if exc.errno != errno.EEXIST:
|
|
||||||
display.warning(
|
|
||||||
"Failed to create the directory '%s': %s" % (ansible_dir, to_text(exc, errors='surrogate_or_replace'))
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
display.debug("Created the '%s' directory" % ansible_dir)
|
|
||||||
|
|
||||||
try:
|
|
||||||
args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv]
|
|
||||||
except UnicodeError:
|
|
||||||
display.error('Command line args are not in utf-8, unable to continue. Ansible currently only understands utf-8')
|
|
||||||
display.display(u"The full traceback was:\n\n%s" % to_text(traceback.format_exc()))
|
|
||||||
exit_code = 6
|
|
||||||
else:
|
|
||||||
cli = mycli(args)
|
|
||||||
exit_code = cli.run()
|
|
||||||
|
|
||||||
except AnsibleOptionsError as e:
|
|
||||||
cli.parser.print_help()
|
|
||||||
display.error(to_text(e), wrap_text=False)
|
|
||||||
exit_code = 5
|
|
||||||
except AnsibleParserError as e:
|
|
||||||
display.error(to_text(e), wrap_text=False)
|
|
||||||
exit_code = 4
|
|
||||||
# TQM takes care of these, but leaving comment to reserve the exit codes
|
|
||||||
# except AnsibleHostUnreachable as e:
|
|
||||||
# display.error(str(e))
|
|
||||||
# exit_code = 3
|
|
||||||
# except AnsibleHostFailed as e:
|
|
||||||
# display.error(str(e))
|
|
||||||
# exit_code = 2
|
|
||||||
except AnsibleError as e:
|
|
||||||
display.error(to_text(e), wrap_text=False)
|
|
||||||
exit_code = 1
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
display.error("User interrupted execution")
|
|
||||||
exit_code = 99
|
|
||||||
except Exception as e:
|
|
||||||
if C.DEFAULT_DEBUG:
|
|
||||||
# Show raw stacktraces in debug mode, It also allow pdb to
|
|
||||||
# enter post mortem mode.
|
|
||||||
raise
|
|
||||||
have_cli_options = bool(context.CLIARGS)
|
|
||||||
display.error("Unexpected Exception, this is probably a bug: %s" % to_text(e), wrap_text=False)
|
|
||||||
if not have_cli_options or have_cli_options and context.CLIARGS['verbosity'] > 2:
|
|
||||||
log_only = False
|
|
||||||
if hasattr(e, 'orig_exc'):
|
|
||||||
display.vvv('\nexception type: %s' % to_text(type(e.orig_exc)))
|
|
||||||
why = to_text(e.orig_exc)
|
|
||||||
if to_text(e) != why:
|
|
||||||
display.vvv('\noriginal msg: %s' % why)
|
|
||||||
else:
|
|
||||||
display.display("to see the full traceback, use -vvv")
|
|
||||||
log_only = True
|
|
||||||
display.display(u"the full traceback was:\n\n%s" % to_text(traceback.format_exc()), log_only=log_only)
|
|
||||||
exit_code = 250
|
|
||||||
|
|
||||||
sys.exit(exit_code)
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from ansible_collections.ansible_community import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1,349 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# Copyright: (c) 2017, Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
import fcntl
|
|
||||||
import hashlib
|
|
||||||
import os
|
|
||||||
import signal
|
|
||||||
import socket
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
import errno
|
|
||||||
import json
|
|
||||||
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
from ansible import constants as C
|
|
||||||
from ansible.module_utils._text import to_bytes, to_text
|
|
||||||
from ansible.module_utils.six import PY3
|
|
||||||
from ansible.module_utils.six.moves import cPickle, StringIO
|
|
||||||
from ansible.module_utils.connection import Connection, ConnectionError, send_data, recv_data
|
|
||||||
from ansible.module_utils.service import fork_process
|
|
||||||
from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder
|
|
||||||
from ansible.playbook.play_context import PlayContext
|
|
||||||
from ansible.plugins.loader import connection_loader
|
|
||||||
from ansible.utils.path import unfrackpath, makedirs_safe
|
|
||||||
from ansible.utils.display import Display
|
|
||||||
from ansible.utils.jsonrpc import JsonRpcServer
|
|
||||||
|
|
||||||
|
|
||||||
def read_stream(byte_stream):
|
|
||||||
size = int(byte_stream.readline().strip())
|
|
||||||
|
|
||||||
data = byte_stream.read(size)
|
|
||||||
if len(data) < size:
|
|
||||||
raise Exception("EOF found before data was complete")
|
|
||||||
|
|
||||||
data_hash = to_text(byte_stream.readline().strip())
|
|
||||||
if data_hash != hashlib.sha1(data).hexdigest():
|
|
||||||
raise Exception("Read {0} bytes, but data did not match checksum".format(size))
|
|
||||||
|
|
||||||
# restore escaped loose \r characters
|
|
||||||
data = data.replace(br'\r', b'\r')
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def file_lock(lock_path):
|
|
||||||
"""
|
|
||||||
Uses contextmanager to create and release a file lock based on the
|
|
||||||
given path. This allows us to create locks using `with file_lock()`
|
|
||||||
to prevent deadlocks related to failure to unlock properly.
|
|
||||||
"""
|
|
||||||
|
|
||||||
lock_fd = os.open(lock_path, os.O_RDWR | os.O_CREAT, 0o600)
|
|
||||||
fcntl.lockf(lock_fd, fcntl.LOCK_EX)
|
|
||||||
yield
|
|
||||||
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
|
||||||
os.close(lock_fd)
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionProcess(object):
|
|
||||||
'''
|
|
||||||
The connection process wraps around a Connection object that manages
|
|
||||||
the connection to a remote device that persists over the playbook
|
|
||||||
'''
|
|
||||||
def __init__(self, fd, play_context, socket_path, original_path, task_uuid=None, ansible_playbook_pid=None):
|
|
||||||
self.play_context = play_context
|
|
||||||
self.socket_path = socket_path
|
|
||||||
self.original_path = original_path
|
|
||||||
self._task_uuid = task_uuid
|
|
||||||
|
|
||||||
self.fd = fd
|
|
||||||
self.exception = None
|
|
||||||
|
|
||||||
self.srv = JsonRpcServer()
|
|
||||||
self.sock = None
|
|
||||||
|
|
||||||
self.connection = None
|
|
||||||
self._ansible_playbook_pid = ansible_playbook_pid
|
|
||||||
|
|
||||||
def start(self, variables):
|
|
||||||
try:
|
|
||||||
messages = list()
|
|
||||||
result = {}
|
|
||||||
|
|
||||||
messages.append(('vvvv', 'control socket path is %s' % self.socket_path))
|
|
||||||
|
|
||||||
# If this is a relative path (~ gets expanded later) then plug the
|
|
||||||
# key's path on to the directory we originally came from, so we can
|
|
||||||
# find it now that our cwd is /
|
|
||||||
if self.play_context.private_key_file and self.play_context.private_key_file[0] not in '~/':
|
|
||||||
self.play_context.private_key_file = os.path.join(self.original_path, self.play_context.private_key_file)
|
|
||||||
self.connection = connection_loader.get(self.play_context.connection, self.play_context, '/dev/null',
|
|
||||||
task_uuid=self._task_uuid, ansible_playbook_pid=self._ansible_playbook_pid)
|
|
||||||
try:
|
|
||||||
self.connection.set_options(var_options=variables)
|
|
||||||
except ConnectionError as exc:
|
|
||||||
messages.append(('debug', to_text(exc)))
|
|
||||||
raise ConnectionError('Unable to decode JSON from response set_options. See the debug log for more information.')
|
|
||||||
|
|
||||||
self.connection._socket_path = self.socket_path
|
|
||||||
self.srv.register(self.connection)
|
|
||||||
messages.extend([('vvvv', msg) for msg in sys.stdout.getvalue().splitlines()])
|
|
||||||
|
|
||||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
||||||
self.sock.bind(self.socket_path)
|
|
||||||
self.sock.listen(1)
|
|
||||||
messages.append(('vvvv', 'local domain socket listeners started successfully'))
|
|
||||||
except Exception as exc:
|
|
||||||
messages.extend(self.connection.pop_messages())
|
|
||||||
result['error'] = to_text(exc)
|
|
||||||
result['exception'] = traceback.format_exc()
|
|
||||||
finally:
|
|
||||||
result['messages'] = messages
|
|
||||||
self.fd.write(json.dumps(result, cls=AnsibleJSONEncoder))
|
|
||||||
self.fd.close()
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
log_messages = self.connection.get_option('persistent_log_messages')
|
|
||||||
while not self.connection._conn_closed:
|
|
||||||
signal.signal(signal.SIGALRM, self.connect_timeout)
|
|
||||||
signal.signal(signal.SIGTERM, self.handler)
|
|
||||||
signal.alarm(self.connection.get_option('persistent_connect_timeout'))
|
|
||||||
|
|
||||||
self.exception = None
|
|
||||||
(s, addr) = self.sock.accept()
|
|
||||||
signal.alarm(0)
|
|
||||||
signal.signal(signal.SIGALRM, self.command_timeout)
|
|
||||||
while True:
|
|
||||||
data = recv_data(s)
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
|
|
||||||
if log_messages:
|
|
||||||
display.display("jsonrpc request: %s" % data, log_only=True)
|
|
||||||
|
|
||||||
request = json.loads(to_text(data, errors='surrogate_or_strict'))
|
|
||||||
if request.get('method') == "exec_command" and not self.connection.connected:
|
|
||||||
self.connection._connect()
|
|
||||||
|
|
||||||
signal.alarm(self.connection.get_option('persistent_command_timeout'))
|
|
||||||
|
|
||||||
resp = self.srv.handle_request(data)
|
|
||||||
signal.alarm(0)
|
|
||||||
|
|
||||||
if log_messages:
|
|
||||||
display.display("jsonrpc response: %s" % resp, log_only=True)
|
|
||||||
|
|
||||||
send_data(s, to_bytes(resp))
|
|
||||||
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
# socket.accept() will raise EINTR if the socket.close() is called
|
|
||||||
if hasattr(e, 'errno'):
|
|
||||||
if e.errno != errno.EINTR:
|
|
||||||
self.exception = traceback.format_exc()
|
|
||||||
else:
|
|
||||||
self.exception = traceback.format_exc()
|
|
||||||
|
|
||||||
finally:
|
|
||||||
# allow time for any exception msg send over socket to receive at other end before shutting down
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
# when done, close the connection properly and cleanup the socket file so it can be recreated
|
|
||||||
self.shutdown()
|
|
||||||
|
|
||||||
def connect_timeout(self, signum, frame):
|
|
||||||
msg = 'persistent connection idle timeout triggered, timeout value is %s secs.\nSee the timeout setting options in the Network Debug and ' \
|
|
||||||
'Troubleshooting Guide.' % self.connection.get_option('persistent_connect_timeout')
|
|
||||||
display.display(msg, log_only=True)
|
|
||||||
raise Exception(msg)
|
|
||||||
|
|
||||||
def command_timeout(self, signum, frame):
|
|
||||||
msg = 'command timeout triggered, timeout value is %s secs.\nSee the timeout setting options in the Network Debug and Troubleshooting Guide.'\
|
|
||||||
% self.connection.get_option('persistent_command_timeout')
|
|
||||||
display.display(msg, log_only=True)
|
|
||||||
raise Exception(msg)
|
|
||||||
|
|
||||||
def handler(self, signum, frame):
|
|
||||||
msg = 'signal handler called with signal %s.' % signum
|
|
||||||
display.display(msg, log_only=True)
|
|
||||||
raise Exception(msg)
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
""" Shuts down the local domain socket
|
|
||||||
"""
|
|
||||||
lock_path = unfrackpath("%s/.ansible_pc_lock_%s" % os.path.split(self.socket_path))
|
|
||||||
if os.path.exists(self.socket_path):
|
|
||||||
try:
|
|
||||||
if self.sock:
|
|
||||||
self.sock.close()
|
|
||||||
if self.connection:
|
|
||||||
self.connection.close()
|
|
||||||
if self.connection.get_option("persistent_log_messages"):
|
|
||||||
for _level, message in self.connection.pop_messages():
|
|
||||||
display.display(message, log_only=True)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
if os.path.exists(self.socket_path):
|
|
||||||
os.remove(self.socket_path)
|
|
||||||
setattr(self.connection, '_socket_path', None)
|
|
||||||
setattr(self.connection, '_connected', False)
|
|
||||||
|
|
||||||
if os.path.exists(lock_path):
|
|
||||||
os.remove(lock_path)
|
|
||||||
|
|
||||||
display.display('shutdown complete', log_only=True)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
""" Called to initiate the connect to the remote device
|
|
||||||
"""
|
|
||||||
rc = 0
|
|
||||||
result = {}
|
|
||||||
messages = list()
|
|
||||||
socket_path = None
|
|
||||||
|
|
||||||
# Need stdin as a byte stream
|
|
||||||
if PY3:
|
|
||||||
stdin = sys.stdin.buffer
|
|
||||||
else:
|
|
||||||
stdin = sys.stdin
|
|
||||||
|
|
||||||
# Note: update the below log capture code after Display.display() is refactored.
|
|
||||||
saved_stdout = sys.stdout
|
|
||||||
sys.stdout = StringIO()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# read the play context data via stdin, which means depickling it
|
|
||||||
vars_data = read_stream(stdin)
|
|
||||||
init_data = read_stream(stdin)
|
|
||||||
|
|
||||||
if PY3:
|
|
||||||
pc_data = cPickle.loads(init_data, encoding='bytes')
|
|
||||||
variables = cPickle.loads(vars_data, encoding='bytes')
|
|
||||||
else:
|
|
||||||
pc_data = cPickle.loads(init_data)
|
|
||||||
variables = cPickle.loads(vars_data)
|
|
||||||
|
|
||||||
play_context = PlayContext()
|
|
||||||
play_context.deserialize(pc_data)
|
|
||||||
display.verbosity = play_context.verbosity
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
rc = 1
|
|
||||||
result.update({
|
|
||||||
'error': to_text(e),
|
|
||||||
'exception': traceback.format_exc()
|
|
||||||
})
|
|
||||||
|
|
||||||
if rc == 0:
|
|
||||||
ssh = connection_loader.get('ssh', class_only=True)
|
|
||||||
ansible_playbook_pid = sys.argv[1]
|
|
||||||
task_uuid = sys.argv[2]
|
|
||||||
cp = ssh._create_control_path(play_context.remote_addr, play_context.port, play_context.remote_user, play_context.connection, ansible_playbook_pid)
|
|
||||||
# create the persistent connection dir if need be and create the paths
|
|
||||||
# which we will be using later
|
|
||||||
tmp_path = unfrackpath(C.PERSISTENT_CONTROL_PATH_DIR)
|
|
||||||
makedirs_safe(tmp_path)
|
|
||||||
|
|
||||||
socket_path = unfrackpath(cp % dict(directory=tmp_path))
|
|
||||||
lock_path = unfrackpath("%s/.ansible_pc_lock_%s" % os.path.split(socket_path))
|
|
||||||
|
|
||||||
with file_lock(lock_path):
|
|
||||||
if not os.path.exists(socket_path):
|
|
||||||
messages.append(('vvvv', 'local domain socket does not exist, starting it'))
|
|
||||||
original_path = os.getcwd()
|
|
||||||
r, w = os.pipe()
|
|
||||||
pid = fork_process()
|
|
||||||
|
|
||||||
if pid == 0:
|
|
||||||
try:
|
|
||||||
os.close(r)
|
|
||||||
wfd = os.fdopen(w, 'w')
|
|
||||||
process = ConnectionProcess(wfd, play_context, socket_path, original_path, task_uuid, ansible_playbook_pid)
|
|
||||||
process.start(variables)
|
|
||||||
except Exception:
|
|
||||||
messages.append(('error', traceback.format_exc()))
|
|
||||||
rc = 1
|
|
||||||
|
|
||||||
if rc == 0:
|
|
||||||
process.run()
|
|
||||||
else:
|
|
||||||
process.shutdown()
|
|
||||||
|
|
||||||
sys.exit(rc)
|
|
||||||
|
|
||||||
else:
|
|
||||||
os.close(w)
|
|
||||||
rfd = os.fdopen(r, 'r')
|
|
||||||
data = json.loads(rfd.read(), cls=AnsibleJSONDecoder)
|
|
||||||
messages.extend(data.pop('messages'))
|
|
||||||
result.update(data)
|
|
||||||
|
|
||||||
else:
|
|
||||||
messages.append(('vvvv', 'found existing local domain socket, using it!'))
|
|
||||||
conn = Connection(socket_path)
|
|
||||||
try:
|
|
||||||
conn.set_options(var_options=variables)
|
|
||||||
except ConnectionError as exc:
|
|
||||||
messages.append(('debug', to_text(exc)))
|
|
||||||
raise ConnectionError('Unable to decode JSON from response set_options. See the debug log for more information.')
|
|
||||||
pc_data = to_text(init_data)
|
|
||||||
try:
|
|
||||||
conn.update_play_context(pc_data)
|
|
||||||
conn.set_check_prompt(task_uuid)
|
|
||||||
except Exception as exc:
|
|
||||||
# Only network_cli has update_play context and set_check_prompt, so missing this is
|
|
||||||
# not fatal e.g. netconf
|
|
||||||
if isinstance(exc, ConnectionError) and getattr(exc, 'code', None) == -32601:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
result.update({
|
|
||||||
'error': to_text(exc),
|
|
||||||
'exception': traceback.format_exc()
|
|
||||||
})
|
|
||||||
|
|
||||||
if os.path.exists(socket_path):
|
|
||||||
messages.extend(Connection(socket_path).pop_messages())
|
|
||||||
messages.append(('vvvv', sys.stdout.getvalue()))
|
|
||||||
result.update({
|
|
||||||
'messages': messages,
|
|
||||||
'socket_path': socket_path
|
|
||||||
})
|
|
||||||
|
|
||||||
sys.stdout = saved_stdout
|
|
||||||
if 'exception' in result:
|
|
||||||
rc = 1
|
|
||||||
sys.stderr.write(json.dumps(result, cls=AnsibleJSONEncoder))
|
|
||||||
else:
|
|
||||||
rc = 0
|
|
||||||
sys.stdout.write(json.dumps(result, cls=AnsibleJSONEncoder))
|
|
||||||
|
|
||||||
sys.exit(rc)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
display = Display()
|
|
||||||
main()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from ansibleplaybookgrapher.cli import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# PYTHON_ARGCOMPLETE_OK
|
|
||||||
"""Command line entry point for ansible-test."""
|
|
||||||
|
|
||||||
# NOTE: This file resides in the _util/target directory to ensure compatibility with all supported Python versions.
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Main program entry point."""
|
|
||||||
ansible_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
source_root = os.path.join(ansible_root, 'test', 'lib')
|
|
||||||
|
|
||||||
if os.path.exists(os.path.join(source_root, 'ansible_test', '_internal', '__init__.py')):
|
|
||||||
# running from source, use that version of ansible-test instead of any version that may already be installed
|
|
||||||
sys.path.insert(0, source_root)
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
|
||||||
from ansible_test._util.target.common.constants import CONTROLLER_PYTHON_VERSIONS
|
|
||||||
|
|
||||||
if version_to_str(sys.version_info[:2]) not in CONTROLLER_PYTHON_VERSIONS:
|
|
||||||
raise SystemExit('This version of ansible-test cannot be executed with Python version %s. Supported Python versions are: %s' % (
|
|
||||||
version_to_str(sys.version_info[:3]), ', '.join(CONTROLLER_PYTHON_VERSIONS)))
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
|
||||||
from ansible_test._internal import main as cli_main
|
|
||||||
|
|
||||||
cli_main()
|
|
||||||
|
|
||||||
|
|
||||||
def version_to_str(version):
|
|
||||||
"""Return a version string from a version tuple."""
|
|
||||||
return '.'.join(str(n) for n in version)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ansible
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from distro.distro import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from compose.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from dotenv.__main__ import cli
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(cli())
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from jsonschema.cli import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from charset_normalizer.cli.normalizer import cli_detect
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(cli_detect())
|
|
||||||
8
bin/pip
8
bin/pip
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
8
bin/pip3
8
bin/pip3
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/opt/ansible/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/usr/bin/python
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
python
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
python
|
|
||||||
240
bin/wsdump.py
240
bin/wsdump.py
@@ -1,240 +0,0 @@
|
|||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
websocket - WebSocket client library for Python
|
|
||||||
|
|
||||||
Copyright (C) 2010 Hiroki Ohtani(liris)
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import code
|
|
||||||
import sys
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
import ssl
|
|
||||||
import gzip
|
|
||||||
import zlib
|
|
||||||
|
|
||||||
import six
|
|
||||||
from six.moves.urllib.parse import urlparse
|
|
||||||
|
|
||||||
import websocket
|
|
||||||
|
|
||||||
try:
|
|
||||||
import readline
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_encoding():
|
|
||||||
encoding = getattr(sys.stdin, "encoding", "")
|
|
||||||
if not encoding:
|
|
||||||
return "utf-8"
|
|
||||||
else:
|
|
||||||
return encoding.lower()
|
|
||||||
|
|
||||||
|
|
||||||
OPCODE_DATA = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
|
|
||||||
ENCODING = get_encoding()
|
|
||||||
|
|
||||||
|
|
||||||
class VAction(argparse.Action):
|
|
||||||
|
|
||||||
def __call__(self, parser, args, values, option_string=None):
|
|
||||||
if values is None:
|
|
||||||
values = "1"
|
|
||||||
try:
|
|
||||||
values = int(values)
|
|
||||||
except ValueError:
|
|
||||||
values = values.count("v") + 1
|
|
||||||
setattr(args, self.dest, values)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
|
||||||
parser = argparse.ArgumentParser(description="WebSocket Simple Dump Tool")
|
|
||||||
parser.add_argument("url", metavar="ws_url",
|
|
||||||
help="websocket url. ex. ws://echo.websocket.org/")
|
|
||||||
parser.add_argument("-p", "--proxy",
|
|
||||||
help="proxy url. ex. http://127.0.0.1:8080")
|
|
||||||
parser.add_argument("-v", "--verbose", default=0, nargs='?', action=VAction,
|
|
||||||
dest="verbose",
|
|
||||||
help="set verbose mode. If set to 1, show opcode. "
|
|
||||||
"If set to 2, enable to trace websocket module")
|
|
||||||
parser.add_argument("-n", "--nocert", action='store_true',
|
|
||||||
help="Ignore invalid SSL cert")
|
|
||||||
parser.add_argument("-r", "--raw", action="store_true",
|
|
||||||
help="raw output")
|
|
||||||
parser.add_argument("-s", "--subprotocols", nargs='*',
|
|
||||||
help="Set subprotocols")
|
|
||||||
parser.add_argument("-o", "--origin",
|
|
||||||
help="Set origin")
|
|
||||||
parser.add_argument("--eof-wait", default=0, type=int,
|
|
||||||
help="wait time(second) after 'EOF' received.")
|
|
||||||
parser.add_argument("-t", "--text",
|
|
||||||
help="Send initial text")
|
|
||||||
parser.add_argument("--timings", action="store_true",
|
|
||||||
help="Print timings in seconds")
|
|
||||||
parser.add_argument("--headers",
|
|
||||||
help="Set custom headers. Use ',' as separator")
|
|
||||||
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
class RawInput:
|
|
||||||
|
|
||||||
def raw_input(self, prompt):
|
|
||||||
if six.PY3:
|
|
||||||
line = input(prompt)
|
|
||||||
else:
|
|
||||||
line = raw_input(prompt)
|
|
||||||
|
|
||||||
if ENCODING and ENCODING != "utf-8" and not isinstance(line, six.text_type):
|
|
||||||
line = line.decode(ENCODING).encode("utf-8")
|
|
||||||
elif isinstance(line, six.text_type):
|
|
||||||
line = line.encode("utf-8")
|
|
||||||
|
|
||||||
return line
|
|
||||||
|
|
||||||
|
|
||||||
class InteractiveConsole(RawInput, code.InteractiveConsole):
|
|
||||||
|
|
||||||
def write(self, data):
|
|
||||||
sys.stdout.write("\033[2K\033[E")
|
|
||||||
# sys.stdout.write("\n")
|
|
||||||
sys.stdout.write("\033[34m< " + data + "\033[39m")
|
|
||||||
sys.stdout.write("\n> ")
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
return self.raw_input("> ")
|
|
||||||
|
|
||||||
|
|
||||||
class NonInteractive(RawInput):
|
|
||||||
|
|
||||||
def write(self, data):
|
|
||||||
sys.stdout.write(data)
|
|
||||||
sys.stdout.write("\n")
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
return self.raw_input("")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
start_time = time.time()
|
|
||||||
args = parse_args()
|
|
||||||
if args.verbose > 1:
|
|
||||||
websocket.enableTrace(True)
|
|
||||||
options = {}
|
|
||||||
if args.proxy:
|
|
||||||
p = urlparse(args.proxy)
|
|
||||||
options["http_proxy_host"] = p.hostname
|
|
||||||
options["http_proxy_port"] = p.port
|
|
||||||
if args.origin:
|
|
||||||
options["origin"] = args.origin
|
|
||||||
if args.subprotocols:
|
|
||||||
options["subprotocols"] = args.subprotocols
|
|
||||||
opts = {}
|
|
||||||
if args.nocert:
|
|
||||||
opts = {"cert_reqs": ssl.CERT_NONE, "check_hostname": False}
|
|
||||||
if args.headers:
|
|
||||||
options['header'] = list(map(str.strip, args.headers.split(',')))
|
|
||||||
ws = websocket.create_connection(args.url, sslopt=opts, **options)
|
|
||||||
if args.raw:
|
|
||||||
console = NonInteractive()
|
|
||||||
else:
|
|
||||||
console = InteractiveConsole()
|
|
||||||
print("Press Ctrl+C to quit")
|
|
||||||
|
|
||||||
def recv():
|
|
||||||
try:
|
|
||||||
frame = ws.recv_frame()
|
|
||||||
except websocket.WebSocketException:
|
|
||||||
return websocket.ABNF.OPCODE_CLOSE, None
|
|
||||||
if not frame:
|
|
||||||
raise websocket.WebSocketException("Not a valid frame %s" % frame)
|
|
||||||
elif frame.opcode in OPCODE_DATA:
|
|
||||||
return frame.opcode, frame.data
|
|
||||||
elif frame.opcode == websocket.ABNF.OPCODE_CLOSE:
|
|
||||||
ws.send_close()
|
|
||||||
return frame.opcode, None
|
|
||||||
elif frame.opcode == websocket.ABNF.OPCODE_PING:
|
|
||||||
ws.pong(frame.data)
|
|
||||||
return frame.opcode, frame.data
|
|
||||||
|
|
||||||
return frame.opcode, frame.data
|
|
||||||
|
|
||||||
def recv_ws():
|
|
||||||
while True:
|
|
||||||
opcode, data = recv()
|
|
||||||
msg = None
|
|
||||||
if six.PY3 and opcode == websocket.ABNF.OPCODE_TEXT and isinstance(data, bytes):
|
|
||||||
data = str(data, "utf-8")
|
|
||||||
if isinstance(data, bytes) and len(data) > 2 and data[:2] == b'\037\213': # gzip magick
|
|
||||||
try:
|
|
||||||
data = "[gzip] " + str(gzip.decompress(data), "utf-8")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
elif isinstance(data, bytes):
|
|
||||||
try:
|
|
||||||
data = "[zlib] " + str(zlib.decompress(data, -zlib.MAX_WBITS), "utf-8")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if isinstance(data, bytes):
|
|
||||||
data = repr(data)
|
|
||||||
|
|
||||||
if args.verbose:
|
|
||||||
msg = "%s: %s" % (websocket.ABNF.OPCODE_MAP.get(opcode), data)
|
|
||||||
else:
|
|
||||||
msg = data
|
|
||||||
|
|
||||||
if msg is not None:
|
|
||||||
if args.timings:
|
|
||||||
console.write(str(time.time() - start_time) + ": " + msg)
|
|
||||||
else:
|
|
||||||
console.write(msg)
|
|
||||||
|
|
||||||
if opcode == websocket.ABNF.OPCODE_CLOSE:
|
|
||||||
break
|
|
||||||
|
|
||||||
thread = threading.Thread(target=recv_ws)
|
|
||||||
thread.daemon = True
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
if args.text:
|
|
||||||
ws.send(args.text)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
message = console.read()
|
|
||||||
ws.send(message)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
return
|
|
||||||
except EOFError:
|
|
||||||
time.sleep(args.eof_wait)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
8
hosts
8
hosts
@@ -1,8 +0,0 @@
|
|||||||
[wattenscheid]
|
|
||||||
192.168.178.210
|
|
||||||
192.168.178.201
|
|
||||||
192.168.178.200
|
|
||||||
|
|
||||||
[vps]
|
|
||||||
eichner.cc
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
home = /usr/bin
|
|
||||||
include-system-site-packages = false
|
|
||||||
version = 3.10.6
|
|
||||||
Reference in New Issue
Block a user