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:
shell: docker run -d -p {{ ansible_eth1.ipv4.address | default(127.0.0.1) }}:27017:27017 [...] dockerfile/mongodb
Unfortunately, Ansible threw the following error:
fatal: [server] => One or more undefined variables: 'ansible_eth1' is undefined
I also tried versions of this, such as:
shell: docker run -d -p {{ ansible_eth1.ipv4.address | ansible_lo.ipv4.address }}:27017:27017 [...] dockerfile/mongodb
That gave me another error:
failed: [server] => {"changed": true, "cmd": "docker run -d -p {# ansible_eth1.ipv4.address | ansible_lo.ipv4.address #}:27017:27017 [...]", "delta": "0:00:00.021053", "end": "2014-11-01 17:22:04.457375", "rc": 127, "start": "2014-11-01 17:22:04.436322"}
stderr: /bin/sh: 1: ansible_lo.ipv4.address: not found
2014/11/01 17:22:04 Invalid containerPort: {{