Closed geerlingguy closed 6 years ago
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @chouseknecht @fabianvf @flaper87 @maxamillion @samdoran click here for bot help
Deprecated?
Workaround I'm using for now is:
- name: Copy Kubernetes definition files to the cluster.
copy:
src: "files/{{ item }}"
dest: "~/{{ item }}"
with_items:
- drupal8.yml
- ...
- name: Apply Drupal 8 Kubernetes services to the cluster.
command: kubectl apply -f ~/{{ item }}
with_items:
- drupal8.yml
- ...
register: drupal8_result
changed_when: "'created' in drupal8_result.stdout"
run_once: True
In Ansible 2.6 the k8s_raw (now k8s) module had a significant rewrite, it will support multiple documents in a file passed with src
. I think the template lookup method still fails (looks like failure is from from_yaml
, not the module), I'll look into allowing it as a string and working around it that way.
@fabianvf - Ah, that explains it!
Hopefully we can stabilize on k8s
for the foreseeable future ;)
I think the YAML library doesn't support reading in the file with multiple documents... but that's based on some fuzzy memory from searching around over the past day, so could be incorrect. If we can use it as a string that would be ideal (IMHO).
@geerlingguy yeah, some people interpreted _raw
as "internal and dangerous", so we figured we'd make it more clear. k8s_raw
and openshift_raw
will still work, they're just aliased to k8s
. I'll try to get a PR in tomorrow for the string thing.
See related: https://github.com/ansible/ansible/issues/42476 — you still can't read a file in directly from the Ansible control machine with multiple definitions and feed it to the k8s
module; you still get an error like:
ComposerError: expected a single document in the stream
in "<unicode string>", line 2, column 1:
apiVersion: v1
^
but found another document
in "<unicode string>", line 7, column 1:
---
^
fatal: [master]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
Therefore, Ansible 2.7 will introduce a new filter, from_yaml_all
, which can be used like:
- k8s:
src: "{{ item }}"
loop: "{{ lookup('template', 'path/to/template.yml') | from_yaml_all }}"
(At least I think.) For now, I'm just copying all the files with multiple definitions to the kubernetes master and running them there instead of parsing/passing the definition(s). It's just easier that way :(
SUMMARY
When using the
k8s_raw
module, if you feed it a document with multiple Kubernetes objects (e.g. aService
and aDeployment
, separated by the YAML document separator---
), then the module will error out withError loading resource_definition: expected a single document in the stream
.In the Kubernetes Configuration Best Practices docs, it's recommended to group all related objects in one file if possible:
The k8s_raw module should support deploying definition files with more than one object.
ISSUE TYPE
COMPONENT NAME
k8s_raw
ANSIBLE VERSION
CONFIGURATION
macOS 10.13.4 High Sierra - host Raspbian 'Stretch' Lite - managed server
STEPS TO REPRODUCE
Kubernetes definition file,
files/drupal8.yml
:Playbook:
EXPECTED RESULTS
The
k8s_raw
module should apply all the definitions in the file, just like runningkubectl -f drupal8.yml
would do on the cluster itself usingkubectl
.ACTUAL RESULTS
The module fails with the following message:
The same failure happens if I:
src
instead ofdefinition
and a lookup (e.g.src: "path/to/drupal8.yml"
).