Skip to content

Instantly share code, notes, and snippets.

@devster31
Created February 5, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/51776b8f46facd8592cad7a0117679f6 to your computer and use it in GitHub Desktop.
Save devster31/51776b8f46facd8592cad7a0117679f6 to your computer and use it in GitHub Desktop.
SUMMARY

query is not returning an empty list.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

query

ANSIBLE VERSION
ansible 2.8.7
  config file = None
  configured module search path = ['/Users/devster/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/devster/code/infrastructure/ansible/env/lib/python3.7/site-packages/ansible
  executable location = /Users/devster/code/infrastructure/ansible/env/bin/ansible
  python version = 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)]
CONFIGURATION

OS / ENVIRONMENT
molecule, version 2.22

docker
Client: Docker Engine - Community
 Version:           19.03.5
# on macOS Catalina 10.15.2

Server: # remote
  Version:          18.06.3-ce
# on Ubuntu 16.04

macOS Catalina 10.15.2
STEPS TO REPRODUCE

Run tasks, described as below. The objective is to grab a file for a specific distribution and version only if it exists.

- include_vars: "{{ item }}"
  loop: "{{ query('first_found', params, errors='ignore') }}"
  vars:
    params:
      files:
        - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml"
      paths:
        - vars

- include_vars: "{{ query('first_found', params, errors='ignore') }}"
  vars:
    params:
      files:
        - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml"
      paths:
        - "vars"

this is the output of the role directory with tree -a:

.
├── .travis.yml
├── .yamllint
├── README.md
├── defaults
│   └── main.yml
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── molecule
│   └── default
│       ├── Dockerfile.j2
│       ├── INSTALL.rst
│       ├── molecule.yml
│       ├── playbook.yml
│       └── tests
│           ├── __pycache__
│           │   ├── test_default.cpython-37-PYTEST.pyc
│           │   └── test_default.cpython-37.pyc
│           └── test_default.py
├── tasks
│   └── main.yml
└── vars
    └── Ubuntu-16.04.yml
EXPECTED RESULTS

include_vars runs with an empty list for all OS except Ubuntu Xenial.

ACTUAL RESULTS

first tasks fails with:

    TASK [rclone : gather OS-specific variables] ***********************************
    task path: /path/to/role/tasks/install.yml:5
    fatal: [ubuntu-bionic]: FAILED! =>
      msg: 'Invalid data passed to ''loop'', it requires a list, got this instead: . Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.'
    ok: [ubuntu-xenial] => (item=/path/to/role/vars/Ubuntu-16.04.yml) => changed=false
      ansible_facts:
        rclone__os_packages:
        - gcc
        - libpython3.5-dev
      ansible_included_var_files:
      - /path/to/role/vars/Ubuntu-16.04.yml
      ansible_loop_var: item
      item: /path/to/role/vars/Ubuntu-16.04.yml

second tasks fails with:

    fatal: [ubuntu-xenial]: FAILED! =>
      msg: '{{ query(''first_found'', params, errors is not a valid option in include_vars'
    fatal: [ubuntu-bionic]: FAILED! =>
      msg: '{{ query(''first_found'', params, errors is not a valid option in include_vars'
    fatal: [debian-buster]: FAILED! =>
      msg: '{{ query(''first_found'', params, errors is not a valid option in include_vars'
    fatal: [debian-stretch]: FAILED! =>
      msg: '{{ query(''first_found'', params, errors is not a valid option in include_vars'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment