mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Add -vvv support for debugging activity
This commit is contained in:
parent
c82f06258c
commit
846186e2fc
10 changed files with 39 additions and 14 deletions
|
@ -122,7 +122,6 @@ class Runner(object):
|
|||
transport=C.DEFAULT_TRANSPORT, # 'ssh', 'paramiko', 'local'
|
||||
conditional='True', # run only if this fact expression evals to true
|
||||
callbacks=None, # used for output
|
||||
verbose=False, # whether to show more or less
|
||||
sudo=False, # whether to run sudo or not
|
||||
sudo_user=C.DEFAULT_SUDO_USER, # ex: 'root'
|
||||
module_vars=None, # a playbooks internals thing
|
||||
|
@ -147,7 +146,6 @@ class Runner(object):
|
|||
self.pattern = pattern
|
||||
self.module_args = module_args
|
||||
self.timeout = timeout
|
||||
self.verbose = verbose
|
||||
self.remote_user = remote_user
|
||||
self.remote_pass = remote_pass
|
||||
self.remote_port = remote_port
|
||||
|
|
|
@ -20,6 +20,7 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
from ansible import errors
|
||||
from ansible.callbacks import vvv
|
||||
|
||||
class LocalConnection(object):
|
||||
''' Local based connections '''
|
||||
|
@ -44,6 +45,7 @@ class LocalConnection(object):
|
|||
raise errors.AnsibleError("sudo with password is presently only supported on the paramiko (SSH) connection type")
|
||||
cmd = "sudo -u {0} -s {1}".format(sudo_user, cmd)
|
||||
|
||||
vvv("EXEC %s" % cmd, host=self.host)
|
||||
p = subprocess.Popen(cmd, shell=True, stdin=None,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
|
@ -52,6 +54,7 @@ class LocalConnection(object):
|
|||
def put_file(self, in_path, out_path):
|
||||
''' transfer a file from local to local '''
|
||||
|
||||
vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
||||
if not os.path.exists(in_path):
|
||||
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
try:
|
||||
|
@ -64,6 +67,7 @@ class LocalConnection(object):
|
|||
raise errors.AnsibleError("failed to transfer file to %s" % out_path)
|
||||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||
''' fetch a file from local to local -- for copatibility '''
|
||||
self.put_file(in_path, out_path)
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import subprocess
|
|||
import pipes
|
||||
import socket
|
||||
import random
|
||||
from ansible import utils
|
||||
from ansible.callbacks import vvv
|
||||
from ansible import errors
|
||||
|
||||
# prevent paramiko warning noise -- see http://stackoverflow.com/questions/3920502/
|
||||
|
@ -84,6 +86,7 @@ class ParamikoConnection(object):
|
|||
|
||||
if not self.runner.sudo or not sudoable:
|
||||
quoted_command = '"$SHELL" -c ' + pipes.quote(cmd)
|
||||
vvv("EXEC %s" % quoted_command, host=self.host)
|
||||
chan.exec_command(quoted_command)
|
||||
else:
|
||||
# Rather than detect if sudo wants a password this time, -k makes
|
||||
|
@ -98,6 +101,7 @@ class ParamikoConnection(object):
|
|||
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
||||
sudocmd = 'sudo -k && sudo -p "%s" -u %s -- "$SHELL" -c %s' % (
|
||||
prompt, sudo_user, pipes.quote(cmd))
|
||||
vvv("EXEC %s" % sudo_cmd, host=self.host)
|
||||
sudo_output = ''
|
||||
try:
|
||||
chan.exec_command(sudocmd)
|
||||
|
@ -120,6 +124,7 @@ class ParamikoConnection(object):
|
|||
|
||||
def put_file(self, in_path, out_path):
|
||||
''' transfer a file from local to remote '''
|
||||
vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
||||
if not os.path.exists(in_path):
|
||||
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
try:
|
||||
|
@ -134,6 +139,7 @@ class ParamikoConnection(object):
|
|||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
''' save a remote file to the specified path '''
|
||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||
try:
|
||||
sftp = self.ssh.open_sftp()
|
||||
except:
|
||||
|
|
|
@ -23,6 +23,7 @@ import pipes
|
|||
import random
|
||||
import select
|
||||
import fcntl
|
||||
from ansible.callbacks import vvv
|
||||
from ansible import errors
|
||||
|
||||
class SSHConnection(object):
|
||||
|
@ -72,6 +73,7 @@ class SSHConnection(object):
|
|||
prompt, sudo_user, pipes.quote(cmd))
|
||||
sudo_output = ''
|
||||
ssh_cmd.append(sudocmd)
|
||||
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
||||
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if self.runner.sudo_pass:
|
||||
|
@ -92,6 +94,7 @@ class SSHConnection(object):
|
|||
fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
|
||||
else:
|
||||
ssh_cmd.append(cmd)
|
||||
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
||||
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
|
@ -114,6 +117,7 @@ class SSHConnection(object):
|
|||
|
||||
def put_file(self, in_path, out_path):
|
||||
''' transfer a file from local to remote '''
|
||||
vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
||||
if not os.path.exists(in_path):
|
||||
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
sftp_cmd = ["sftp"] + self.common_args + [self.host]
|
||||
|
@ -125,6 +129,7 @@ class SSHConnection(object):
|
|||
|
||||
def fetch_file(self, in_path, out_path):
|
||||
''' fetch a file from remote to local '''
|
||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||
sftp_cmd = ["sftp"] + self.common_args + [self.host]
|
||||
p = subprocess.Popen(sftp_cmd, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue