From 08596fd05ba7190a04e7112270a38a0ce32095dd Mon Sep 17 00:00:00 2001 From: Mauricio Teixeira <1847440+badnetmask@users.noreply.github.com> Date: Wed, 21 Sep 2022 09:51:54 -0400 Subject: [PATCH] Add example usage of from_yaml_all (#505) Add example usage of from_yaml_all Depends-On: #513 SUMMARY Sometimes one might want to use a single YAML file that contains multiple Kubernetes definitions. This PR updates the documentation to provide a simple example of how to accomplish that. ISSUE TYPE Docs Pull Request COMPONENT NAME k8s ADDITIONAL INFORMATION I have not tested this solution against other modules, simply because I did not have use-case for those. Reviewed-by: Mike Graves --- changelogs/fragments/505-add-from-yaml-all-example.yml | 3 +++ plugins/modules/k8s.py | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/505-add-from-yaml-all-example.yml diff --git a/changelogs/fragments/505-add-from-yaml-all-example.yml b/changelogs/fragments/505-add-from-yaml-all-example.yml new file mode 100644 index 0000000000..12773cccf5 --- /dev/null +++ b/changelogs/fragments/505-add-from-yaml-all-example.yml @@ -0,0 +1,3 @@ +--- +trivial: + - add example usage for from_yaml_all (https://github.com/ansible-collections/kubernetes.core/pull/505). diff --git a/plugins/modules/k8s.py b/plugins/modules/k8s.py index 31e5099e05..9b284d15d3 100644 --- a/plugins/modules/k8s.py +++ b/plugins/modules/k8s.py @@ -232,6 +232,14 @@ state: present definition: "{{ lookup('file', '/testing/deployment.yml') | from_yaml }}" +- name: >- + (Alternative) Read definition file from the Ansible controller file system. + In this case, the definition file contains multiple YAML documents, separated by ---. + If the definition file has been encrypted with Ansible Vault it will automatically be decrypted. + kubernetes.core.k8s: + state: present + definition: "{{ lookup('file', '/testing/deployment.yml') | from_yaml_all }}" + - name: Read definition template file from the Ansible controller file system kubernetes.core.k8s: state: present