From 36ae2f2a76c312ccd98b5eed1180e21d012b36c8 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sun, 8 May 2022 02:06:57 +0200 Subject: [PATCH] Added ansible templating example --- ansible/templating-tests.yml | 4 ++++ knowledge base/ansible.md | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ansible/templating-tests.yml b/ansible/templating-tests.yml index e5633b6..fb509b4 100644 --- a/ansible/templating-tests.yml +++ b/ansible/templating-tests.yml @@ -74,3 +74,7 @@ salt: "{{ lookup('community.general.random_string', special=false) }}" ansible.builtin.debug: var: password | password_hash('sha512', salt) + + - name: Get a variable's type. + ansible.builtin.debug: + var: "'string' | type_debug" diff --git a/knowledge base/ansible.md b/knowledge base/ansible.md index 5978cdd..404a158 100644 --- a/knowledge base/ansible.md +++ b/knowledge base/ansible.md @@ -121,12 +121,18 @@ ansible-galaxy remove namespace.role salt: "{{ lookup('community.general.random_string', special=false) }}" ansible.builtin.debug: var: password | password_hash('sha512', salt) + +- name: Get a variable's type. + ansible.builtin.debug: + var: "'string' | type_debug" ``` ## Loops ```yaml -- name: Fail when one of the given variables is an empty string. +- name: >- + Fail when any of the given variables is an empty string. + Returns the ones which are. when: lookup('vars', item) == '' ansible.builtin.fail: msg: "The {{ item }} variable is an empty string"