diff --git a/ans-run-demo-lowercase-sr.sh b/ans-run-demo-lowercase-sr.sh new file mode 100644 index 0000000..56d94e0 --- /dev/null +++ b/ans-run-demo-lowercase-sr.sh @@ -0,0 +1,3 @@ +#!/bin/bash +ansible-playbook -i localhost demo-ansible-lowercase-search-replace.yml + diff --git a/demo-ansible-lowercase-search-replace.yml b/demo-ansible-lowercase-search-replace.yml new file mode 100644 index 0000000..0de2ff5 --- /dev/null +++ b/demo-ansible-lowercase-search-replace.yml @@ -0,0 +1,24 @@ +--- +- name: Demo lowercase and search/replace in var + hosts: localhost + gather_facts: false + vars: + answers: "no so YES no" + +# mastering ansible 4th ed. 2021, p.202 +# REF: https://stackoverflow.com/questions/55927273/how-ansible-assign-values-to-variables +# REF: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html + +# replace all no with yes and lowercase it all + tasks: + - name: do the thing + debug: + msg: + - "Original: {{ answers }}" + - "Expected result: {{ answers | replace('no', 'yes') | lower }}" + + - set_fact: my_result="{{ answers | replace('no', 'yes') | lower }}" + + - name: show result + debug: + msg: "{{ my_result }}"