This is not the exact same code. If you look carefully at the example, you'll see that under users, you have several dicts.

In your case, you have two dicts but with just one key (alice, or telephone) with respective values of "Alice", 123.

You'd rather do :

- hosts: localhost
  gather_facts: no
  tasks:
    - name: print phone details
      debug: msg="user {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
      with_dict: "{{ users }}"
  vars:
    users:
      alice:
        name: "Alice"
        telephone: 123

(note that I changed host to localhost so I can run it easily, and added gather_facts: no since it's not necessary here. YMMV.)

Answer from leucos on Stack Overflow
🌐
GitHub
github.com › ansible › ansible › issues › 30944
"dict object has no attribute" with default() filter · Issue #30944 · ansible/ansible
September 26, 2017 - Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'mydict'"} Reactions are currently unavailable ·
Author   ansible
Discussions

'dict object' has no attribute.... - Ansible Project - Ansible
I’ve been working this issue for a week now. The code used to work perfectly and now it fails. Here is the error I get: The task includes an option with an undefined variable. The error was: {‘CentOS’: ‘{{ iptables_dire… More on forum.ansible.com
🌐 forum.ansible.com
0
February 13, 2024
ansible 2.x - Why am i getting "AnsibleUndefinedVariable: 'dict object' has no attribute 'default_ipv4'" - Stack Overflow
TASK [all hosts to be added to /etc/hosts] ********************************************************************* An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'default_ipv4' ... More on stackoverflow.com
🌐 stackoverflow.com
Ansible 'dict object' has no attribute 'stdout'"
Summary Hi Guys! I have problem with ansible Then i execute my playbook. I get error ""VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'"". name: show version hosts: telnet gather_f... More on github.com
🌐 github.com
9
May 3, 2021
argument_spec: default value for dict entries do not work
Summary In argument_spec configuring a dict key and inside that key options with default values. The default value will not be supplied. Issue Type Bug Report Component Name bin/ansible validate_ar... More on github.com
🌐 github.com
9
May 21, 2024
🌐
OneUptime
oneuptime.com › home › blog › how to fix ansible dictionary object has no attribute errors
How to Fix Ansible dictionary object has no attribute Errors
February 21, 2026 - It is one of the most common variable-related errors in Ansible. fatal: [server1]: FAILED! => { "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'nonexistent_key'" } # Problem: accessing a key that is not present - debug: msg: "{{ my_dict.missing_key }}" # Fix: use the default filter - debug: msg: "{{ my_dict.missing_key | default('N/A') }}" # Or use bracket notation with default - debug: msg: "{{ my_dict['missing_key'] | default('N/A') }}"
🌐
Ansible
forum.ansible.com › archives › ansible project
'dict object' has no attribute.... - Ansible Project - Ansible
February 13, 2024 - I’ve been working this issue for a week now. The code used to work perfectly and now it fails. Here is the error I get: The task includes an option with an undefined variable. The error was: {‘CentOS’: ‘{{ iptables_directory[ansible_distribution] }}/iptables’, ‘Rocky’: ‘{{ iptables_directory[ansible_distribution] }}/iptables’, ‘Debian’: ‘{{ iptables_directory[ansible_distribution] }}/rules.v4’, ‘Ubuntu’: ‘{{ iptables_directory[ansible_distribution] }}/rules.v4’}: ‘dict object’ has no attribut...
🌐
Bobcares
bobcares.com › blog › how-to-fix-ansible-error-dict-object-has-no-attribute
How to Fix Ansible Error 'dict object' Has No Attribute
December 18, 2025 - Second, never trust module outputs without checking documentation. Third, use default() filters wherever data may be optional. Most importantly, write defensive playbooks. Assume data can be missing. Because one day, it will be. The Ansible error ‘dict object’ has no attribute isn’t a bug.
🌐
Google Groups
groups.google.com › g › ansible-project › c › rHM11nJNBdo
Ansible Playbook error - Dict object has no attribute.
I am trying to create a Direct ... using ansible. I have the main playbook and an account config yaml template. When I run the playbook I am getting an error · fatal: [infrastructure]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stacks'\n\nThe ...
Find elsewhere
🌐
Ansiblebyexample
ansiblebyexample.com › home › tutorials › troubleshooting › fix ansible "dict object has no attribute" error — variable access guide
Fix Ansible "dict object has no attribute" Error — Variable Access Guide
March 3, 2026 - # RISKY — any level could be ...k.interfaces.eth0 | default({})).ip | default('none') }}" Always use | default() when accessing dictionary keys that might not exist....
🌐
GitHub
github.com › ansible › ansible › issues › 74552
Ansible 'dict object' has no attribute 'stdout'" · Issue #74552 · ansible/ansible
May 3, 2021 - $ ansible-config dump --only-changed name: show version hosts: telnet gather_facts: false # connection: local tasks: - name: CM via telnet telnet: login_prompt: "User name: " prompts: - '[#]' command: - show version - show lldp info remote register: telnet_output - debug: var=telnet_output.stdout.lines ok: [sw1] => { "telnet_output.stdout.lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'" } META: ran handlers META: ran handlers PLAY RECAP ************************************************************************************************************************************************************ sw1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible@ansible:~$
Author   ansible
🌐
GitHub
github.com › ansible › ansible › issues › 83287
argument_spec: default value for dict entries do not work · Issue #83287 · ansible/ansible
May 21, 2024 - Summary In argument_spec configuring a dict key and inside that key options with default values. The default value will not be supplied. Issue Type Bug Report Component Name bin/ansible validate_ar...
Author   ansible
🌐
Medium
medium.com › opsops › fighting-with-limitation-of-default-filter-in-jinja2-ansible-a39c47096b9c
Fighting with limitation of ‘|default()’ filter in jinja2 (ansible) | by George Shuklin | OpsOps | Medium
June 3, 2018 - - hosts: all gather_facts: no tasks: - debug: var=optdict2.value|default("ok") vars: optdict1: '{{ mydict.optdict1|default({}) }}' optdict2: '{{ optdict1.optionaldict2|default({}) }}' vars: mydict: Keeping Ansible playbooks readable is not a question of aesthetic, it’s a question of sanity.
🌐
Reddit
reddit.com › r/ansible › why 'dict object' has no attribute?
r/ansible on Reddit: Why 'dict object' has no attribute?
January 9, 2020 -

I'm struggling agains this problem.

That's my variable file:

distribution_major_version: 18
prereq_packages:
    16:
      - 1
      - 2
      - 3
    18:
      - 4
      - 5
      - 6

This playbook works:

---
  -
    hosts: localhost
    tasks:
    - name: Print string from manifest
      debug:
        msg: "{{prereq_packages[distribution_major_version] }}"

this not:

---
  -
    hosts: localhost
    tasks:
    - name: Print string from manifest
      debug:
        msg: "{{prereq_packages[ansible_distribution_major_version] }}"

with this error:

TASK [Print string from manifest] *******************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'18'\n\nThe error appears to be in '/home/local/RISORSA/gorgellino/playbook/local/prova_variabili.yml': line 5, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    tasks:\n    - name: Print string from manifest\n      ^ here\n"}
Top answer
1 of 1
1
The error occurs because the key you are using to access prereq_packages is a string (str), while the dictionary keys are integers (int). 🔍 Explanation: In the first playbook, you access the variable using distribution_major_version, which is explicitly defined as an integer (18). In the second playbook, you use ansible_distribution_major_version, which Ansible treats as a string ("18"), not an integer. As a result, it tries to access prereq_packages["18"], but the available key is 18 (integer), not "18" (string). 🛠 Solution: Convert ansible_distribution_major_version to an integer in your playbook: --- - hosts: localhost tasks: - name: Print string from manifest debug: msg: "{{ prereq_packages[ansible_distribution_major_version | int] }}" 🔹 The | int filter forces the variable to be converted to an integer, allowing proper dictionary key access. ✅ With this fix, your playbook will work without errors.The error occurs because the key you are using to access prereq_packages is a string (str), while the dictionary keys are integers (int). 🔍 Explanation: In the first playbook, you access the variable using distribution_major_version, which is explicitly defined as an integer (18). In the second playbook, you use ansible_distribution_major_version, which Ansible treats as a string ("18"), not an integer. As a result, it tries to access prereq_packages["18"], but the available key is 18 (integer), not "18" (string). 🛠 Solution: Convert ansible_distribution_major_version to an integer in your playbook: --- - hosts: localhost tasks: - name: Print string from manifest debug: msg: "{{ prereq_packages[ansible_distribution_major_version | int] }}" 🔹 The | int filter forces the variable to be converted to an integer, allowing proper dictionary key access. ✅ With this fix, your playbook will work without errors.
🌐
GitHub
github.com › ansible › ansible › issues › 35873
AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_default_ipv4'" · Issue #35873 · ansible/ansible
July 2, 2018 - AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_default_ipv4'"#35873 · Copy link · Labels ·
Author   ansible
🌐
Middleware Inventory
middlewareinventory.com › blog › ansible-dict-object-has-no-attribute-stdout-or-stderr-how-to-resolve
Ansible dict object has no attribute stdout (or) stderr - How to Resolve
June 19, 2022 - In this post, we will discuss how ... has no attribute" error. ... Ansible will throw this error when you are trying to display the stdout (or) stderr of a task during playbook runtime....
🌐
Google Groups
groups.google.com › g › ansible-project › c › irvn6QeOB_w
'dict object' has no attribute....
The error was: {'CentOS': '{{ iptables_directory[ansible_distribution] }}/iptables', 'Rocky': '{{ iptables_directory[ansible_distribution] }}/iptables', 'Debian': '{{ iptables_directory[ansible_distribution] }}/rules.v4', 'Ubuntu': '{{ iptables_directory[ansible_distribution] }}/rules.v4'}: 'dict object' has no attribute 'CentOS'. 'dict object' has no attribute 'CentOS'. The error appears to be in '/work/armory/roles/xxx/tasks/xxx.yml': line 266, column 3, but may be elsewhere in the file depending on the exact syntax problem. Default.yml is at the playbook level in a folder called group_vars.
🌐
Reddit
reddit.com › r/ansible › guys, help me pleaze! 'dict object' has no attribute 'stdout'
r/ansible on Reddit: guys, help me pleaze! 'dict object' has no attribute 'stdout'
April 11, 2018 -

I am trying to get only a portion of the ouput of a command and store the value in a list (for future looping)

tasks: - name: Execute the command win_shell: <command> register: <variable> with_items: - <host1> - <host2>

 - name: print the variable
   debug: var=<variable>

gives this output:

ok: [immgt4] => { "msg": { "changed": true, "msg": "All items completed", "results": [ { "_ansible_ignore_errors": null, "_ansible_item_result": true, "_ansible_no_log": false, "_ansible_parsed": true, "changed": true, "cmd": "Install-Module -Name VMware.PowerCLI -scope CurrentUser;Connect-Viserver vcyow -Credential (Import-clixml c:\pkgs\vm.clixml) -Force > null;(get-vmhost -Name esxfbsmesg1.corp.navcan.ca | get-vm).name", "delta": "0:00:08.615218", "end": "2018-04-11 06:06:34.589090", "failed": false, "item": "esxfbsmesg1.corp.navcan.ca", "rc": 0, "start": "2018-04-11 06:06:25.973871", "stderr": "", "stderr_lines": [], "stdout": "test-host-patching3\r\ntest-host-patching1\r\ntest-host-patching\r\n", "stdout_lines": [ "test-host-patching3", "test-host-patching1", "test-host-patching" ] }, { "_ansible_ignore_errors": null, "_ansible_item_result": true, "_ansible_no_log": false, "_ansible_parsed": true, "changed": true, "cmd": "Install-Module -Name VMware.PowerCLI -scope CurrentUser;Connect-Viserver vcyow -Credential (Import-clixml c:\pkgs\vm.clixml) -Force > null;(get-vmhost -Name esxfbsmesg2a.corp.navcan.ca | get-vm).name", "delta": "0:00:09.022712", "end": "2018-04-11 06:06:44.424300", "failed": false, "item": "esxfbsmesg2a.corp.navcan.ca", "rc": 0, "start": "2018-04-11 06:06:35.401588", "stderr": "", "stderr_lines": [], "stdout": "test-host-patching5\r\ntest-vm-snapshot4\r\n", "stdout_lines": [ "test-host-patching5", "test-vm-snapshot4" ] } ] } }

question: How can i store only the stdout_lines into a new variable it being a list?

when i try anything of the sort of: debug: var=list_vms.stdout

I get this error: The error was: 'dict object' has no attribute 'stdout'

I am very new to ansible and would appreciate your help!

thanks!

The goal for me is to get the result from the first command, put it in a variable and loop trough that list for another command.

Top answer
1 of 5
6
I am betting your problem is almost certainly related to the fact that you are using register in a task with a loop (ie with_items). You need to remember that the results are going to come back as an array. http://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#using-register-with-a-loop How you handle that, depends on how you need to use the results. There are methods that you can use a map to extract the properties you want.
2 of 5
2
when i try anything of the sort of: debug: var=list_vms.stdout, I get this error: The error was: 'dict object' has no attribute 'stdout' Well look at the structure of the debug command's output: "msg": { "changed": , "msg": , "results": [ { "": , "stdout": "test-host-patching3\r\ntest-host-patching1\r\ntest-host-patching\r\n", "stdout_lines": [ "test-host-patching3", "test-host-patching1", "test-host-patching" ] }, ... This is "just" regular JSON . msg is a dictionary. Access values of keys either via msg.key, via msg['key'] or via msg.get('key'). There are subtle differences between each method, but it's easiest to "just" understand Python and dictionaries, then you'll automatically get that. []denotes a list. Lists can either be accessed by index or iterated. You do not have key access. List objects can either be "simple" values like strings, integers, etc. or "complex" objects like dictionaries, lists, etc. Applying this logic and comparing with the structure you see, that the variable list_vms.stdout does not exist: You have to iterate list_vms.results. In trivial python code that's: result = list() for entry in list_vms.results: result.append(entry.stdout) In order to do this in Ansible playbooks, you have to look at filters . The ones you want to have a closer look are JMESPath and Jinja's builtin filters , most importantly the map filter. The basic usage is mapping on an attribute. Imagine you have a list of users but you are only interested in a list of usernames: Users: {{ users|map(attribute='username')|join(', ') }} What you essentially want to do is access {{ list_vms.results | map(attribute='stdout') | list }} For completeness sake: | list is required, because map will always return an iterator .
🌐
Reddit
reddit.com › r/ansible › ansibleundefinedvariable: 'dict object' has no attribute 'ansible_default_ipv4'
r/ansible on Reddit: AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_default_ipv4'
August 29, 2017 -

I have the following template, which stopped working

{% for host in groups['execd'] %}
{{ hostvars[host]['ansible_default_ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_fqdn'] }}
{% endfor %}

it started throwing this error: AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_default_ipv4'

I tried it on versions:

  • ansible 2.4.0 (devel 8e6c0ca599)

  • ansible 2.0.0.2

Anyone having an idea why this doesn't work anymore ?

EDIT: I just figured it out, one of my hosts in my inventory was unreachable (it's a test environment). removing it from the inventory solves the problem

🌐
GitHub
github.com › ansible › ansible › issues › 22729
'dict object' has no attribute in when clause 2.3 RC1 · Issue #22729 · ansible/ansible
March 17, 2017 - ansible 2.3.0.0 (stable-2.3 923c9ef17c) last updated 2017/03/17 09:12:40 (GMT +1000) config file = /apps/dev/playbook/jordan/mr-ansible/ansible.cfg configured module search path = Default w/o overrides python version = 2.7.12 (default, Sep 23 2016, 14:23:49) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] ... This may not be a bug but just something I got away with on older versions but with Ansible 2.3 RC1 if I am checking if a variable registered by a module (with an when clause) is defined and then subsequently get a sub dict value it will fail in 2.3 while in 2.2 and below it works fine.
Author   ansible
🌐
Reddit
reddit.com › r/ansible › ansible stat module error 'dict object' has no attribute 'exists'
r/ansible on Reddit: Ansible stat module error 'dict object' has no attribute 'exists'
November 20, 2020 -

I'm trying to use the Ansible module stat to determine if /etc/snmp/snmpd.conf exists or not.

This is the contents of the .yml file

--- # v-72313 must remove snmp community strings

- hosts: rhel7-servers

user: ansible

become: yes

become_user: root

connection: ssh

gather_facts: no

tasks:

- name: V-72313 must remove snmp community strings

stat:

path: /etc/snmp/snmpd.conf

register: s

- debug:

msg: "Path exists and is a directory"

when: s.exists

- debug:

msg: "Path and file not found"

when: s.exists == False

When I run this, it displays the following error:

fatal: [192.168.100.2]: FAILED! =>

msg: |-

The conditional check 't.exists == True' failed. The error was: error while evaluating conditional (t.exists == True): 'dict object' has no attribute 'exists'

The error appears to be in '/home/ansible/playbooks/stig_high/test_path.yml': line 13, column 5, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

register: t

- debug:

^ here

fatal: [192.168.100.3]: FAILED! =>

msg: |-

The conditional check 't.exists == True' failed. The error was: error while evaluating conditional (t.exists == True): 'dict object' has no attribute 'exists'

The error appears to be in '/home/ansible/playbooks/stig_high/test_path.yml': line 13, column 5, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

register: t

- debug:

^ here

fatal: [192.168.100.4]: FAILED! =>

msg: |-

The conditional check 't.exists == True' failed. The error was: error while evaluating conditional (t.exists == True): 'dict object' has no attribute 'exists'

The error appears to be in '/home/ansible/playbooks/stig_high/test_path.yml': line 13, column 5, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

register: t

- debug:

^ here

PLAY RECAP ********************************************************************************************************************************************************************************************************

192.168.100.2: ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

192.168.100.3: ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

192.168.100.4: ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

I've hit a dead end with this and can't figure out why.

I created a generic test directory under /tmp with a subdirectory and some files in it on a remote test server just to see if I would get the same output and I am. So its something that I'm doing with the syntax of the yml.