fix bug - k8s was crashing when yaml ended with 3 dashes (#61182)

* fix bug - k8s was crashing when yaml ended with 3 dashes

* #61182 - add changelog
This commit is contained in:
Michał Szczepańczyk 2019-08-26 09:28:01 +02:00 committed by Will Thames
parent 7e1a347695
commit 8ed3a0b360
3 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- k8s module - fix for case when resource definition yaml ended with 3 dashes

View file

@ -136,6 +136,10 @@ class KubernetesRawModule(KubernetesAnsibleModule):
src = self.params.get('src') src = self.params.get('src')
if src: if src:
self.resource_definitions = self.load_resource_definitions(src) self.resource_definitions = self.load_resource_definitions(src)
try:
self.resource_definitions = [item for item in self.resource_definitions if item]
except AttributeError:
pass
if not resource_definition and not src: if not resource_definition and not src:
implicit_definition = dict( implicit_definition = dict(

View file

@ -312,12 +312,29 @@
- testing5 - testing5
register: k8s_info register: k8s_info
- name: Resources are terminating if still in results - name: Resources are terminating if still in results
assert: assert:
that: not item.resources or item.resources[0].status.phase == "Terminating" that: not item.resources or item.resources[0].status.phase == "Terminating"
loop: "{{ k8s_info.results }}" loop: "{{ k8s_info.results }}"
- name: Create resources from a yaml string ending with ---
k8s:
definition: |+
---
kind: Namespace
apiVersion: v1
metadata:
name: testing6
---
- name: Namespace should exist
k8s_info:
kind: Namespace
api_version: v1
name: testing6
register: k8s_info_testing6
failed_when: not k8s_info_testing6.resources or k8s_info_testing6.resources[0].status.phase != "Active"
- include_tasks: crd.yml - include_tasks: crd.yml
- include_tasks: lists.yml - include_tasks: lists.yml
- include_tasks: append_hash.yml - include_tasks: append_hash.yml
@ -351,4 +368,8 @@
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: testing5 name: testing5
- kind: Namespace
apiVersion: v1
metadata:
name: testing6
ignore_errors: yes ignore_errors: yes