Added ansible templating example

This commit is contained in:
Michele Cereda
2022-05-08 02:06:57 +02:00
parent 6a6ee6e251
commit 36ae2f2a76
2 changed files with 11 additions and 1 deletions

View File

@@ -74,3 +74,7 @@
salt: "{{ lookup('community.general.random_string', special=false) }}" salt: "{{ lookup('community.general.random_string', special=false) }}"
ansible.builtin.debug: ansible.builtin.debug:
var: password | password_hash('sha512', salt) var: password | password_hash('sha512', salt)
- name: Get a variable's type.
ansible.builtin.debug:
var: "'string' | type_debug"

View File

@@ -121,12 +121,18 @@ ansible-galaxy remove namespace.role
salt: "{{ lookup('community.general.random_string', special=false) }}" salt: "{{ lookup('community.general.random_string', special=false) }}"
ansible.builtin.debug: ansible.builtin.debug:
var: password | password_hash('sha512', salt) var: password | password_hash('sha512', salt)
- name: Get a variable's type.
ansible.builtin.debug:
var: "'string' | type_debug"
``` ```
## Loops ## Loops
```yaml ```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) == '' when: lookup('vars', item) == ''
ansible.builtin.fail: ansible.builtin.fail:
msg: "The {{ item }} variable is an empty string" msg: "The {{ item }} variable is an empty string"