Allow fireball to transfer binary files, fixup fireball docs, make fetch work with fireball.
This commit is contained in:
parent
8c0f83a2c9
commit
096607eea4
3 changed files with 18 additions and 9 deletions
|
@ -623,7 +623,7 @@ if you have a large number of hosts::
|
||||||
# set up the fireball transport
|
# set up the fireball transport
|
||||||
- hosts: all
|
- hosts: all
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
connection: ssh
|
connection: ssh # or paramiko
|
||||||
sudo: True
|
sudo: True
|
||||||
tasks:
|
tasks:
|
||||||
- action: fireball
|
- action: fireball
|
||||||
|
@ -631,7 +631,6 @@ if you have a large number of hosts::
|
||||||
# these operations will occur over the fireball transport
|
# these operations will occur over the fireball transport
|
||||||
- hosts: all
|
- hosts: all
|
||||||
connection: fireball
|
connection: fireball
|
||||||
sudo: True
|
|
||||||
tasks:
|
tasks:
|
||||||
- action: shell echo "Hello ${item}"
|
- action: shell echo "Hello ${item}"
|
||||||
with_items:
|
with_items:
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import base64
|
||||||
from ansible.callbacks import vvv
|
from ansible.callbacks import vvv
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
|
@ -97,8 +98,10 @@ class Connection(object):
|
||||||
if not os.path.exists(in_path):
|
if not os.path.exists(in_path):
|
||||||
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||||
data = file(in_path).read()
|
data = file(in_path).read()
|
||||||
|
data = base64.b64encode(data)
|
||||||
|
|
||||||
data = dict(mode='put', data=data, out_path=out_path)
|
data = dict(mode='put', data=data, out_path=out_path)
|
||||||
|
# TODO: support chunked file transfer
|
||||||
data = utils.jsonify(data)
|
data = utils.jsonify(data)
|
||||||
data = utils.encrypt(self.key, data)
|
data = utils.encrypt(self.key, data)
|
||||||
self.socket.send(data)
|
self.socket.send(data)
|
||||||
|
@ -113,7 +116,7 @@ class Connection(object):
|
||||||
''' save a remote file to the specified path '''
|
''' save a remote file to the specified path '''
|
||||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||||
|
|
||||||
data = dict(mode='fetch', file=in_path)
|
data = dict(mode='fetch', in_path=in_path)
|
||||||
data = utils.jsonify(data)
|
data = utils.jsonify(data)
|
||||||
data = utils.encrypt(self.key, data)
|
data = utils.encrypt(self.key, data)
|
||||||
self.socket.send(data)
|
self.socket.send(data)
|
||||||
|
@ -122,6 +125,7 @@ class Connection(object):
|
||||||
response = utils.decrypt(self.key, response)
|
response = utils.decrypt(self.key, response)
|
||||||
response = utils.parse_json(response)
|
response = utils.parse_json(response)
|
||||||
response = response['data']
|
response = response['data']
|
||||||
|
response = base64.b64decode(response)
|
||||||
|
|
||||||
fh = open(out_path, "w")
|
fh = open(out_path, "w")
|
||||||
fh.write(response)
|
fh.write(response)
|
||||||
|
|
|
@ -162,13 +162,15 @@ def command(data):
|
||||||
return dict(stdout=stdout, stderr=stderr)
|
return dict(stdout=stdout, stderr=stderr)
|
||||||
|
|
||||||
def fetch(data):
|
def fetch(data):
|
||||||
if 'data' not in data:
|
|
||||||
return dict(failed=True, msg='internal error: data is required')
|
|
||||||
if 'in_path' not in data:
|
if 'in_path' not in data:
|
||||||
return dict(failed=True, msg='internal error: out_path is required')
|
return dict(failed=True, msg='internal error: in_path is required')
|
||||||
|
|
||||||
|
# FIXME: should probably support chunked file transfer for binary files
|
||||||
|
# at some point. For now, just base64 encodes the file
|
||||||
|
# so don't use it to move ISOs, use rsync.
|
||||||
|
|
||||||
fh = open(data['in_path'])
|
fh = open(data['in_path'])
|
||||||
data = fh.read()
|
data = base64.b64encode(fh.read())
|
||||||
return dict(data=data)
|
return dict(data=data)
|
||||||
|
|
||||||
def put(data):
|
def put(data):
|
||||||
|
@ -177,9 +179,13 @@ def put(data):
|
||||||
return dict(failed=True, msg='internal error: data is required')
|
return dict(failed=True, msg='internal error: data is required')
|
||||||
if 'out_path' not in data:
|
if 'out_path' not in data:
|
||||||
return dict(failed=True, msg='internal error: out_path is required')
|
return dict(failed=True, msg='internal error: out_path is required')
|
||||||
|
|
||||||
|
# FIXME: should probably support chunked file transfer for binary files
|
||||||
|
# at some point. For now, just base64 encodes the file
|
||||||
|
# so don't use it to move ISOs, use rsync.
|
||||||
|
|
||||||
fh = open(data['out_path'], 'w')
|
fh = open(data['out_path'], 'w')
|
||||||
fh.write(data['data'])
|
fh.write(base64.b64decode(data['data']))
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
return dict()
|
return dict()
|
||||||
|
|
Loading…
Reference in a new issue