VARIABLE IS NOT DEFINED when trying to register output in playbook

Jota picture Jota · Mar 25, 2019 · Viewed 9.4k times · Source

I'm trying to register a variable with the output to a query of a F5 pool and I'm getting this error:

"<type 'list'>": "VARIABLE IS NOT DEFINED!", 

What is that I'm doing wrong? Any help appreciated. Thanks!

---
- name: GRAB F5 FACTS
  hosts: f5
  connection: local
  gather_facts: no
  tasks:
    - name: Collect BIG-IP facts
      bigip_device_facts:
        gather_subset: ltm-pools
        provider: "{{ prov }}"
      register: bigip_device_facts

    - name: FACTS OUTPUT
      debug:
        var: "{{ item.members | rejectattr('state', 'match', '^present$') | map(attribute='name') | list }}"
      register: jkout
      with_items: "{{ bigip_device_facts.ltm_pools }}" 
      when: item.full_path  == "/Common/mypool"

    - name: Set a variable
      debug:
        msg: "jkvar={{ jkout }}"

Answer

dgw picture dgw · Mar 25, 2019

You are using the debug: module with the option var: and this expects a variable, not a jinja2 template.

So either change it to:

debug:
  var: item.members

or

debug:
  msg: "{{ item.members }}"