Skip to content

Commit

Permalink
k8s: Add a parameter remote_src
Browse files Browse the repository at this point in the history
remote_src is boolean parameter to specify if
src file is located on remote node or Ansible Controller.

Fixes: ansible-collections#307

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Dec 3, 2020
1 parent 11191e4 commit e7736a8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/307_remote_src.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- k8s - add parameter to specify if src file is located on remote node and not on Ansible Controller (https://github.com/ansible-collections/community.kubernetes/issues/307).
16 changes: 12 additions & 4 deletions plugins/action/k8s_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ def run(self, tmp=None, task_vars=None):

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

if src:
if remote_src:
# src is on remote node
result.update(self._execute_module(module_name=self._task.action, task_vars=task_vars))
return self._ensure_invocation(result)

try:
# find in expected paths
src = self._find_needle('files', src)
Expand Down Expand Up @@ -117,10 +124,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 +146,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
7 changes: 7 additions & 0 deletions plugins/doc_fragments/k8s_resource_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ class ModuleDocFragment(object):
I(resource_definition). See Examples below.
- Mutually exclusive with I(template) in case of M(k8s) module.
type: path
remote_src:
description:
- Set to C(yes) to indicate the I(src) file is already on the remote system and not local to the Ansible controller.
- This is not valid for I(template) parameter.
type: bool
default: False
version_added: "1.2.0"
'''
4 changes: 4 additions & 0 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def list_dict_str(value):
'src': {
'type': 'path',
},
'remote_src': {
'type': 'bool',
'default': False,
},
}

NAME_ARG_SPEC = {
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/targets/kubernetes/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- pip:
name:
- openshift>=0.9.2
- coverage
- coverage==5.0.4
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no
Expand All @@ -36,7 +36,7 @@
name:
- kubernetes-validate==1.12.0
- openshift>=0.9.2
- coverage
- coverage==5.0.4
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no
Expand All @@ -57,7 +57,7 @@
name:
- kubernetes==12.0.0
- openshift>=0.9.2
- coverage
- coverage==5.0.4
virtualenv: "{{ virtualenv }}"
virtualenv_command: "{{ virtualenv_command }}"
virtualenv_site_packages: no
Expand All @@ -73,7 +73,6 @@
no_log: yes

# Test openshift

- debug:
var: k8s_openshift

Expand Down

0 comments on commit e7736a8

Please sign in to comment.