mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-06 21:12:37 +00:00
k8s_cp - a new module for copying files to/from a Pod (#127)
* k8s_cp module * add documentation for k8s_cp module * add doc for the new module * pods should be running * support for binary, archive and zip file * sanity * Delete file.txt * remove unused * set back * Update collection.txt * Update test_copy_errors.yml * Update plugins/modules/k8s_cp.py Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> * Update k8s_cp.py * Update k8s_cp.py * tar binary requirements * Update common.py * Update k8s_cp.py * Update k8s_cp.py * replace kind with binary file * Update test_copy_large_file.yml * Update plugins/action/k8s_info.py Co-authored-by: Mike Graves <mgraves@redhat.com> * Update k8s_info.py * Update k8s_info.py * Update k8s_cp.py Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
1
plugins/action/k8s_cp.py
Symbolic link
1
plugins/action/k8s_cp.py
Symbolic link
@@ -0,0 +1 @@
|
||||
k8s_info.py
|
||||
@@ -8,6 +8,7 @@ __metaclass__ = type
|
||||
|
||||
import copy
|
||||
import traceback
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
@@ -179,6 +180,20 @@ class ActionModule(ActionBase):
|
||||
new_module_args.pop('template')
|
||||
new_module_args['definition'] = result_template
|
||||
|
||||
def get_file_realpath(self, local_path):
|
||||
# local_path is only supported by k8s_cp module.
|
||||
if self._task.action not in ('k8s_cp', 'kubernetes.core.k8s_cp', 'community.kubernetes.k8s_cp'):
|
||||
raise AnsibleActionFail("'local_path' is only supported parameter for 'k8s_cp' module.")
|
||||
|
||||
if os.path.exists(local_path):
|
||||
return local_path
|
||||
|
||||
try:
|
||||
# find in expected paths
|
||||
return self._find_needle('files', local_path)
|
||||
except AnsibleError:
|
||||
raise AnsibleActionFail("%s does not exist in local filesystem" % local_path)
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
''' handler for k8s options '''
|
||||
if task_vars is None:
|
||||
@@ -238,6 +253,11 @@ class ActionModule(ActionBase):
|
||||
if template:
|
||||
self.load_template(template, new_module_args, task_vars)
|
||||
|
||||
local_path = self._task.args.get('local_path')
|
||||
state = self._task.args.get('state', None)
|
||||
if local_path and state == 'to_pod':
|
||||
new_module_args['local_path'] = self.get_file_realpath(local_path)
|
||||
|
||||
# Execute the k8s_* module.
|
||||
module_return = self._execute_module(module_name=self._task.action, module_args=new_module_args, task_vars=task_vars)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user