1

I'm at my wits ends with this. I have YAML that looks like this:

network_interface_scripts:
  -
    interface: eth0
    lifecycle_entries:
      -
        commands:
          - "route add -net 172.17.2.0 netmask 255.255.255.0 gw 172.17.70.1 eth0"
          - "route add -net 10.102.0.0 netmask 255.255.0.0 gw 172.17.70.1 eth0"
        script_name: interface_eth0_up
        trigger_on: post-up
      -
        commands:
          - "route delete -net 172.17.2.0 netmask 255.255.255.0 gw 172.17.70.1 eth0"
          - "route delete -net 10.102.0.0 netmask 255.255.0.0 gw 172.17.70.1 eth0"
        script_name: interface_eth0_down
        trigger_on: pre-down

and I have an ansible task that's like

- name: Check that trigger_on has valid value
  fail: msg="trigger_on has invalid value. Allowed values are pre-up, up, post-up, pre-down, down and post-down"
  when: item.1.trigger_on != "pre-up" and item.1.trigger_on != "up" and item.1.trigger_on != "post-up" and item.1.trigger_on != "pre-down" and item.1.trigger_on != "down" and item.1.trigger_on != "post-down"
  with_subelements:
    - network_interface_scripts | default([])
    - lifecycle_entries

This always fails with:

fatal: [fe1.prod.somedomain.de]: FAILED! => {"failed": true, "msg": "subelements lookup expects a dictionary, got 'network_interface_scripts | default([])'"}

I tried an online validator for the dictionary, which said it was valid YAML. What am I missing? Why does ansible not recognize this as a dictionary?

edit: Ansible version is 2.2.0.0, search didn't turn up anything useful ... sry if this has been asked before

Michael Niemand
  • 1,578
  • 3
  • 23
  • 39

1 Answers1

5

Like Konstaintin said: It's treating network_interface_scripts as the string literal 'network_interface_scripts'.

Instead try:

with_subelements:
- "{{ network_interface_scripts | default([]) }}"
- "{{ lifecycle_entries }}"
GJZ
  • 2,482
  • 3
  • 21
  • 37
kangolo
  • 66
  • 1
  • 1
    This solved the problem partly, when I did it like this it returned an "lifecycle_entries is undefined" error, so I had to put - lifecycle_entries without the brackets and quotes. – Michael Niemand Dec 10 '16 at 12:44