Strange lookup behavior after ansible 2.2

25 views
Skip to first unread message

Vyacheslav

unread,
Dec 8, 2016, 2:46:21 PM12/8/16
to Ansible Project
Hi,

Assuming I have lookup plugins of such form:

Single

============================================

"""
"""
from __future__ import (absolute_import, division, print_function)
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase

__metaclass__ = type


class LookupModule(LookupBase):

    def run(self, terms, variables=None, **kwargs):
        result="single_row"
        return [result]

============================================

Multiple

============================================

"""
"""
from __future__ import (absolute_import, division, print_function)
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase

__metaclass__ = type


class LookupModule(LookupBase):

    def run(self, terms, variables=None, **kwargs):
        result=[ "row1", "row2"]
        return [result]



============================================

Play:

============================================

  - block:

    - name: Lookup 1
      set_fact:
        lookup1: "{{lookup('single')}}"

    - debug: var="lookup1"

    - name: Lookup 2
      set_fact:
        lookup2: "{{lookup('multiple')}}"

    - debug: var="lookup2"

    - set_fact:
        previously_it_was_working: "{{lookup1[0]}}"

    - set_fact:
        now_only_this_working: "{{lookup2[0]}}"


    - debug: msg="This debug should not be skipped {{previously_it_was_working}}"

    - debug: msg="This debug should not be skipped too {{now_only_this_working}}"

    - shell: "echo This might be errored but not skipped {{previously_it_was_working}}. And was working in Ansible 2.1"

    - shell: "echo This might be errored too but definitely not skipped {{now_only_this_working}}}. And was working in Ansible 2.1"

    - debug: msg="Nice to meet you http://github.com/voronenko"

    when: 1==1


============================================


Expected result:  returned array in both cases.

Side effect:  in more complex production play actions like below now sometimes are just skipped?

    - debug: msg="This debug should not be skipped {{previously_it_was_working}}"

    - shell: "echo This might be errored but not skipped {{previously_it_was_working}}. And was working in Ansible 2.1"

Instead I have play:

=======================
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides

PLAY [Test play] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [Lookup 1] ****************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "lookup1": "single_row"
}

TASK [Lookup 2] ****************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "lookup2": [
        "row1", 
        "row2"
    ]
}

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "This debug should not be skipped s"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "This debug should not be skipped too row1"
}

TASK [command] *****************************************************************
changed: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "Nice to meet you http://github.com/voronenko"
}

PLAY RECAP *********************************************************************
localhost                  : ok=12   changed=2    unreachable=0    failed=0  
========================
Reply all
Reply to author
Forward
0 new messages