Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

k8s: handle remote src and kubeconfig #320

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/307_remote_src.yml
Original file line number Diff line number Diff line change
@@ -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).
29 changes: 22 additions & 7 deletions plugins/action/k8s_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
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)

kubeconfig = self._task.args.get('kubeconfig', None)
# find the file in the expected search path
if kubeconfig:
# find the kubeconfig in the expected search path
if kubeconfig and not remote_transport:
# kubeconfig is local
try:
# find in expected paths
kubeconfig = self._find_needle('files', kubeconfig)
Expand All @@ -55,14 +63,20 @@ def run(self, tmp=None, task_vars=None):
result['exception'] = traceback.format_exc()
return result

if kubeconfig:
# decrypt kubeconfig found
actual_file = self._loader.get_real_file(kubeconfig, decrypt=True)
new_module_args['kubeconfig'] = actual_file

# find the file in the expected search path
src = self._task.args.get('src', None)

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:
# find in expected paths
src = self._find_needle('files', src)
Expand Down Expand Up @@ -117,10 +131,6 @@ def run(self, tmp=None, task_vars=None):
else:
raise AnsibleActionFail("Error while reading template file - "
"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.
if lstrip_blocks:
Expand All @@ -143,6 +153,11 @@ def run(self, tmp=None, task_vars=None):
elif newline_sequence not in allowed_sequences:
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
try:
tmp_source = self._loader.get_real_file(source)
Expand Down