--- - hosts: localhost gather_facts: no tasks: - name: Strings in a loop are indeed defined ignore_errors: true assert: that: item is defined loop: - RandomStringA - RandomStringB - ansible_forks - name: Strings in a loop are unlikely to be variable names ignore_errors: true assert: that: '{{ item }} is defined' loop: - UndefinedVariableNameA - UndefinedVariableNameB - ansible_forks
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d23f849b-0342-47d8-b2f4-0f1634cdf866n%40googlegroups.com.
-- Todd
% ansible --version
ansible [core 2.16.4]
config file = None
configured module search path = ['/Users/wrowe/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
ansible collection location = /Users/wrowe/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.11.8 (main, Feb 6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/opt/homebrew/opt/pyt...@3.11/bin/python3.11)
jinja version = 3.1.3
libyaml = True
% ansible-playbook foo.yaml -i localhost,
PLAY [localhost] *******************************************************************************************************
TASK [without templating] **********************************************************************************************
ok: [localhost] => (item=varA) => {
"ansible_loop_var": "item",
"changed": false,
"item": "varA",
"msg": "All assertions passed"
}
ok: [localhost] => (item=varB) => {
"ansible_loop_var": "item",
"changed": false,
"item": "varB",
"msg": "All assertions passed"
}
TASK [with templating] *************************************************************************************************
failed: [localhost] (item=varA) => {
"ansible_loop_var": "item",
"assertion": "varA is defined",
"changed": false,
"evaluated_to": false,
"item": "varA",
"msg": "Assertion failed"
}
failed: [localhost] (item=varB) => {
"ansible_loop_var": "item",
"assertion": "varB is defined",
"changed": false,
"evaluated_to": false,
"item": "varB",
"msg": "Assertion failed"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4ea45f07-c044-4b61-a244-e6f2d5980ed6%40gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/fqqYt8AfU_o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/A767305C-C137-4E0B-B1FD-DAAC2DDD32A6%40nist.gov.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMc-rNNuhejhhNGzOfoQOq8MOLT6bBCjvgakLN6us8OSVVLDcA%40mail.gmail.com.
% cat foo.yml
---
- hosts: localhost
gather_facts: no
become: no
tasks:
- name: without templating
assert:
that: "{{ item }} is defined"
loop:
- varA
- varB
% ansible-playbook -i localhost, foo.yml -e varB=string
PLAY [localhost] *******************************************************************************************************
TASK [without templating] **********************************************************************************************
failed: [localhost] (item=varA) => {
"ansible_loop_var": "item",
"assertion": "varA is defined",
"changed": false,
"evaluated_to": false,
"item": "varA",
"msg": "Assertion failed"
}
ok: [localhost] => (item=varB) => {
"ansible_loop_var": "item",
"changed": false,
"item": "varB",
"msg": "All assertions passed"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMc-rNNuhejhhNGzOfoQOq8MOLT6bBCjvgakLN6us8OSVVLDcA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v-0K-MtnAHAwOfv5of2KU2fXMvuFdUKe1-1WRyWhN%3DKmA%40mail.gmail.com.
also varnames lookup
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/fqqYt8AfU_o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7chFT4FkH0NGn2AuAG62-c2ZqvGxbn7HAJ19RzKN93EJA%40mail.gmail.com.