Last active
June 10, 2016 17:38
-
-
Save codyaray/9138c7a55c4fe507b98305518268324c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/stackstorm/st2/bin/python | |
import paramiko | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect('svwchi6padmin1', username='sslcertsvcs', password='soopersecret', allow_agent=False, look_for_keys=False) | |
stdin,stdout,stderr = ssh.exec_command('export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"') | |
print stdout.read() | |
### OUTPUT | |
# $ ./paramiko_raw.py | |
# sslcertsvcs | |
# Volume in drive \\svwchi6padmin1\c$ has no label. | |
# Volume Serial Number is 5CA5-F15B | |
# | |
# Directory of \\svwchi6padmin1\c$ | |
# <snip> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/stackstorm/st2/bin/python | |
import paramiko | |
from StringIO import StringIO | |
import time | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect('svwchi6padmin1', username='sslcertsvcs', password='soopersecret', allow_agent=False, look_for_keys=False) | |
transport = ssh.get_transport() | |
chan = transport.open_session() | |
start_time = time.time() | |
chan.exec_command('export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"') | |
stdout = StringIO() | |
stderr = StringIO() | |
bufsize = -1 | |
stdin = chan.makefile('wb', bufsize) | |
stdin.close() | |
exit_status_ready = chan.exit_status_ready() | |
stdout = chan.makefile('rb', bufsize) | |
stderr = chan.makefile_stderr('rb', bufsize) | |
print stdout.read() | |
### OUTPUT | |
# $ ./paramiko_raw.py | |
# sslcertsvcs | |
# Volume in drive \\svwchi6padmin1\c$ has no label. | |
# Volume Serial Number is 5CA5-F15B | |
# | |
# Directory of \\svwchi6padmin1\c$ | |
# <snip> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/stackstorm/st2/bin/python | |
import paramiko | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect('svwchi6padmin1', username='sslcertsvcs', password='soopersecret', allow_agent=False, look_for_keys=False) | |
# just opening and closing this ftp causes Access Denied on the exec_command | |
ftp=ssh.open_sftp() | |
ftp.close() | |
stdin,stdout,stderr = ssh.exec_command('export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"') | |
print stdout.read() | |
print stderr.read() | |
### OUTPUT | |
# $ ./paramiko_raw.py | |
# sslcertsvcs | |
# | |
# Access is denied. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/stackstorm/st2/bin/python | |
from st2common.script_setup import setup as common_setup | |
from st2common import config | |
from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient | |
common_setup(config=config, setup_db=True, register_mq_exchanges=True) | |
client = ParamikoSSHClient('svwchi6padmin1', username='sslcertsvcs', password='soopersecret', key_material=None, passphrase=None, port=22) | |
client.connect() | |
stdout, stderr, status = client.run('export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad3df70608e630434e960 ST2_ACTION_AUTH_TOKEN=89837e8f3b4a4201b27fdbb24d079b21 ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"') | |
print stdout, stderr, status | |
### OUTPUT | |
# $ ./paramiko_st2.py --config-file /etc/st2/st2.conf | |
# 2016-06-10 11:20:24,702 INFO [-] Connecting to database "st2" @ "localhost:27017" as user "None". | |
# 2016-06-10 11:20:24,821 INFO [-] Connected (version 2.0, client OpenSSH_7.2) | |
# 2016-06-10 11:20:25,157 INFO [-] Authentication (password) successful! | |
# 2016-06-10 11:20:25,309 INFO [-] [chan 0] Opened sftp connection (server version 3) | |
# 2016-06-10 11:20:25,310 INFO [-] Executing command | |
# Access is denied. 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,329 140326210375344 DEBUG base [-] Performing pre-run for runner: 99086e14-d465-49b3-933f-4597268e4c86 | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,329", "thread": 140326210375344, "levelname": "DEBUG", "module": "base", "message": "Performing pre-run for runner: 99086e14-d465-49b3-933f-4597268e4c86"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,330 140326210375344 DEBUG paramiko_ssh_runner [-] Entering BaseParallelSSHRunner.pre_run() for liveaction_id="575ad62870608e21f4147915" | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,330", "thread": 140326210375344, "levelname": "DEBUG", "module": "paramiko_ssh_runner", "message": "Entering BaseParallelSSHRunner.pre_run() for liveaction_id=\"575ad62870608e21f4147915\""} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,330 140326210375344 INFO paramiko_ssh_runner [-] [BaseParallelSSHRunner="99086e14-d465-49b3-933f-4597268e4c86", liveaction_id="575ad62870608e21f4147915"] Finished pre_run. | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,330", "thread": 140326210375344, "levelname": "INFO", "module": "paramiko_ssh_runner", "message": "[BaseParallelSSHRunner=\"99086e14-d465-49b3-933f-4597268e4c86\", liveaction_id=\"575ad62870608e21f4147915\"] Finished pre_run."} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,331 140326194304176 DEBUG ip_utils [-] Non-bracket address. host_str: svwchi6padmin1 | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,331", "thread": 140326194304176, "levelname": "DEBUG", "module": "ip_utils", "message": "Non-bracket address. host_str: svwchi6padmin1"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,331 140326194304176 DEBUG parallel_ssh [-] Connecting to host. (host=u'svwchi6padmin1',password='********',user=u'sslcertsvcs',port=22) | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,331", "thread": 140326194304176, "levelname": "DEBUG", "module": "parallel_ssh", "message": "Connecting to host."} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,332 140326194304176 DEBUG paramiko_ssh [-] Connecting to server (timeout=60,username=u'sslcertsvcs',hostname=u'svwchi6padmin1',port=22) | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,332", "thread": 140326194304176, "levelname": "DEBUG", "module": "paramiko_ssh", "message": "Connecting to server"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,834 140326210375344 DEBUG parallel_ssh [-] Connect to hosts complete. (_connect_results={u'svwchi6padmin1': {'message': 'Connected to host.'}}) | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,834", "thread": 140326210375344, "levelname": "DEBUG", "module": "parallel_ssh", "message": "Connect to hosts complete."} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,835 140326210375344 DEBUG base [-] Performing run for runner: 99086e14-d465-49b3-933f-4597268e4c86 (parameters={'action_parameters': {}, 'runner_parameters': {u'username': u'sslcertsvcs', u'private_key': '********', u'sudo': False, u'env': None, u'cmd': u'whoami; cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"', u'port': 22, u'parallel': False, u'kwarg_op': u'--', u'bastion_host': None, u'hosts': u'svwchi6padmin1', u'dir': u'/tmp', u'timeout': 60, u'password': '********', u'cwd': u'/tmp', u'passphrase': '********'}},runner='<st2actions.runners.remote_command_runner.ParamikoRemoteCommandRunner object at 0x7fa03c906150>') | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,835", "thread": 140326210375344, "levelname": "DEBUG", "module": "base", "message": "Performing run for runner: 99086e14-d465-49b3-933f-4597268e4c86"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,837 140326210375344 WARNING api [-] "auth.api_url" configuration option is not configured | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,837", "thread": 140326210375344, "levelname": "WARNING", "module": "api", "message": "\"auth.api_url\" configuration option is not configured"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,838 140326210375344 DEBUG remote_command_runner [-] Executing remote command action. (_action_params='<st2common.models.system.paramiko_command_action.ParamikoRemoteCommandAction object at 0x7fa03c8ceb10>') | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,838", "thread": 140326210375344, "levelname": "DEBUG", "module": "remote_command_runner", "message": "Executing remote command action."} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,839 140326210375344 DEBUG paramiko_command_action [-] Command to run on remote host will be: export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\svwchi6padmin1\c$" | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,839", "thread": 140326210375344, "levelname": "DEBUG", "module": "paramiko_command_action", "message": "Command to run on remote host will be: export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c \"dir \\\\\\\\svwchi6padmin1\\c$\""} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,839 140326194304176 DEBUG parallel_ssh [-] Running command: export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\svwchi6padmin1\c$" on host: svwchi6padmin1. | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,839", "thread": 140326194304176, "levelname": "DEBUG", "module": "parallel_ssh", "message": "Running command: export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c \"dir \\\\\\\\svwchi6padmin1\\c$\" on host: svwchi6padmin1."} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:57,840 140326194304176 INFO paramiko_ssh [-] Executing command (cmd=u'export ST2_ACTION_PACK_NAME=winjobs ST2_ACTION_EXECUTION_ID=575ad62870608e21f4147916 ST2_ACTION_AUTH_TOKEN=7cb848d7bf1f4cc3b951e359bc79690e ST2_ACTION_API_URL=http://127.0.0.1:9101/v1 && cd /tmp && whoami; cmd /c "dir \\\\\\\\svwchi6padmin1\\c$"') | |
==> /plogs/st2/st2actionrunner.8478.audit.log <== | |
{"asctime": "2016-06-10 10:00:57,840", "thread": 140326194304176, "levelname": "INFO", "module": "paramiko_ssh", "message": "Executing command"} | |
==> /plogs/st2/st2actionrunner.8478.log <== | |
2016-06-10 10:00:59,358 140326194304176 DEBUG paramiko_ssh [-] Command finished (stderr=u'Access is denied.',status=1,stdout=u'sslcertsvcs') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment