On Wed, 5 Feb 2020 06:23:08 -0800 (PST) Devesh singh <[email protected]> wrote:
> error was: template error while templating string: no filter named 'match'.
>
> when:
> - ansible_{{ Detrio_backup_nic
> }}.ipv4.network|*match*(Detrio_backup_network)
There are 2 problems
1) "match" is a test. See "Testing strings"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings
2) Use "lookup" and "vars" plugin to get value of dynamically created
variable's name. See "vars – Lookup templated value of variables"
https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html#vars-lookup-templated-value-of-variables
For example
- set_fact:
Detrio_has_backup_nic: true
vars:
my_nic: "{{ lookup('vars', 'ansible_' ~ Detrio_backup_nic) }}
when:
- my_nic.ipv4.network is match(Detrio_backup_network)
- _has_backup_nic is undefined
- Detrio_backup_nic is defined
HTH,
-vlado
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20200205162038.2af1cd05%40gmail.com.
pgpw6H7Yqwzbv.pgp
Description: OpenPGP digital signature
