Jinja2 is a little more picky about using dot notation as opposed to []
type notation as it pertains to using "default"
You might want to try:
ansible_eth1["ipv4"]["address"] | default("127.0.0.1")
You may also need to place the default closer to ansible_eth1 as opposed to
deeper nesting like it is currently.
On Saturday, November 1, 2014, Viktor Petersson <[email protected]> wrote:
> Hey guys,
>
>
> 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: {{
>
> Could anyone help point me in the right direction?
>
> I've also published this on Serverfault [1]:
>
> http://serverfault.com/questions/641326/issues-with-ansibles-default-error-handling-in-a-playbook
>
> --
> 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]
> <javascript:_e(%7B%7D,'cvml','ansible-project%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ad7a8411-abbe-46b9-bff7-a9a122eb115d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ad7a8411-abbe-46b9-bff7-a9a122eb115d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9WhfCPX4vntyBcwt8O8VvhcMaRE3NeUrAOO8oNukSckg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.