mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-14 05:22:08 +00:00
k8s: handle remote src and kubeconfig (#320)
* k8s: Add a parameter remote_src remote_src is boolean parameter to specify if src file is located on remote node or Ansible Controller. Fixes: #307 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * remove parameters Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
3
changelogs/fragments/307_remote_src.yml
Normal file
3
changelogs/fragments/307_remote_src.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
minor_changes:
|
||||||
|
- k8s - check if src file is located on remote node or on Ansible Controller (https://github.com/ansible-collections/community.kubernetes/issues/307).
|
||||||
|
- k8s - check if kubeconfig file is located on remote node or on Ansible Controller (https://github.com/ansible-collections/community.kubernetes/issues/307).
|
||||||
@@ -42,10 +42,18 @@ class ActionModule(ActionBase):
|
|||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
result = super(ActionModule, self).run(tmp, task_vars)
|
||||||
del tmp # tmp no longer has any effect
|
del tmp # tmp no longer has any effect
|
||||||
|
|
||||||
|
# Check current transport connection and depending upon
|
||||||
|
# look for kubeconfig and src
|
||||||
|
# 'local' => look files on Ansible Controller
|
||||||
|
# Transport other than 'local' => look files on remote node
|
||||||
|
remote_transport = self._connection.transport != 'local'
|
||||||
|
|
||||||
new_module_args = copy.deepcopy(self._task.args)
|
new_module_args = copy.deepcopy(self._task.args)
|
||||||
|
|
||||||
kubeconfig = self._task.args.get('kubeconfig', None)
|
kubeconfig = self._task.args.get('kubeconfig', None)
|
||||||
# find the file in the expected search path
|
# find the kubeconfig in the expected search path
|
||||||
if kubeconfig:
|
if kubeconfig and not remote_transport:
|
||||||
|
# kubeconfig is local
|
||||||
try:
|
try:
|
||||||
# find in expected paths
|
# find in expected paths
|
||||||
kubeconfig = self._find_needle('files', kubeconfig)
|
kubeconfig = self._find_needle('files', kubeconfig)
|
||||||
@@ -55,14 +63,20 @@ class ActionModule(ActionBase):
|
|||||||
result['exception'] = traceback.format_exc()
|
result['exception'] = traceback.format_exc()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if kubeconfig:
|
|
||||||
# decrypt kubeconfig found
|
# decrypt kubeconfig found
|
||||||
actual_file = self._loader.get_real_file(kubeconfig, decrypt=True)
|
actual_file = self._loader.get_real_file(kubeconfig, decrypt=True)
|
||||||
new_module_args['kubeconfig'] = actual_file
|
new_module_args['kubeconfig'] = actual_file
|
||||||
|
|
||||||
# find the file in the expected search path
|
# find the file in the expected search path
|
||||||
src = self._task.args.get('src', None)
|
src = self._task.args.get('src', None)
|
||||||
|
|
||||||
if src:
|
if src:
|
||||||
|
if remote_transport:
|
||||||
|
# src is on remote node
|
||||||
|
result.update(self._execute_module(module_name=self._task.action, task_vars=task_vars))
|
||||||
|
return self._ensure_invocation(result)
|
||||||
|
|
||||||
|
# src is local
|
||||||
try:
|
try:
|
||||||
# find in expected paths
|
# find in expected paths
|
||||||
src = self._find_needle('files', src)
|
src = self._find_needle('files', src)
|
||||||
@@ -117,10 +131,6 @@ class ActionModule(ActionBase):
|
|||||||
else:
|
else:
|
||||||
raise AnsibleActionFail("Error while reading template file - "
|
raise AnsibleActionFail("Error while reading template file - "
|
||||||
"a string or dict for template expected, but got %s instead" % type(template))
|
"a string or dict for template expected, but got %s instead" % type(template))
|
||||||
try:
|
|
||||||
source = self._find_needle('templates', template_path)
|
|
||||||
except AnsibleError as e:
|
|
||||||
raise AnsibleActionFail(to_text(e))
|
|
||||||
|
|
||||||
# Option `lstrip_blocks' was added in Jinja2 version 2.7.
|
# Option `lstrip_blocks' was added in Jinja2 version 2.7.
|
||||||
if lstrip_blocks:
|
if lstrip_blocks:
|
||||||
@@ -143,6 +153,11 @@ class ActionModule(ActionBase):
|
|||||||
elif newline_sequence not in allowed_sequences:
|
elif newline_sequence not in allowed_sequences:
|
||||||
raise AnsibleActionFail("newline_sequence needs to be one of: \n, \r or \r\n")
|
raise AnsibleActionFail("newline_sequence needs to be one of: \n, \r or \r\n")
|
||||||
|
|
||||||
|
try:
|
||||||
|
source = self._find_needle('templates', template_path)
|
||||||
|
except AnsibleError as e:
|
||||||
|
raise AnsibleActionFail(to_text(e))
|
||||||
|
|
||||||
# Get vault decrypted tmp file
|
# Get vault decrypted tmp file
|
||||||
try:
|
try:
|
||||||
tmp_source = self._loader.get_real_file(source)
|
tmp_source = self._loader.get_real_file(source)
|
||||||
|
|||||||
Reference in New Issue
Block a user