I’m trying to write an ansible playbook with the shell module. In the command, I’m want to use the eth1 interface if it exists. If the eth1 interface doesn’t exist, it should fallback to the loopback interface.
My initial approach was to use the defaulting undefined variables as follows:
I tried this and it didn’t work. Is it supposed to? Is there some other way of using default that would work? Would it make sense to fix the default filter to work in this case?
Try with
default(“127.0.0.1”, true)
It is not clear on the filter description, but without the second argument it does not perform a boolean evaluation, but just strict variable undefinition. That means that an empty string will not trigger the default. Actually, even if the variable you are testing is None, the default will not be used.
It is not clear on the filter description, but without the second argument it does not perform a boolean evaluation, but just strict variable undefinition. That means that an empty string will not trigger the default. Actually, even if the variable you are testing is None, the default will not be used.
I’m sorry, I didn’t specify that I’m getting the same “One or more undefined variables” as Viktor was. The undefined variable can be in my case be on any level. So for ansible_eth1.ipv4.address any of ansible_eth1, ipv4 or address could be undefined.