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
🌐
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...
Discussions

"dict object has no attribute" with default() filter
ISSUE TYPE Bug Report COMPONENT NAME default() filter ANSIBLE VERSION 2.4.0.0 OS / ENVIRONMENT Fedora 26 SUMMARY default() fails with "dict object has no attribute" error if variable does not exist. STEPS TO REPRODUCE - hosts: localhost ... More on github.com
🌐 github.com
6
September 26, 2017
Why 'dict object' has no attribute?
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. More on reddit.com
🌐 r/ansible
1
2
January 9, 2020
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
Ansible stat module error 'dict object' has no attribute 'exists'

I think you need to check s.stat.exists.

If you use debug to print s right after the stat task you'll see the layout of the variable.

More on reddit.com
🌐 r/ansible
2
3
November 20, 2020
🌐
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 - "Dictionary has no attribute" errors mean you are trying to access a key that does not exist. Use | default() to handle missing keys gracefully, print the full variable with debug: var: to see its actual structure, and use | dict2items when ...
🌐
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 - The Ansible error ‘dict object’ has no attribute appears when your playbook tries to read a key that doesn’t exist in a dictionary.
🌐
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'"}
Author   ansible
🌐
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 › 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
Find elsewhere
🌐
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 ...
🌐
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.

🌐
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 - # This fails if gather_facts: false - debug: msg: "{{ ansible_distribution }}" # Fix: ensure facts are gathered - hosts: all gather_facts: true ... # RISKY — any level could be missing - debug: msg: "{{ server.network.interfaces.eth0.ip }}" # SAFE — chain defaults - debug: msg: "{{ (server.network.interfaces.eth0 | default({})).ip | default('none') }}" Always use | default() when accessing dictionary keys that might not exist.
🌐
Coderanch
coderanch.com › t › 778373 › os › resolve-dict-object-attribute-files
How to resolve 'dict object' has no attribute 'files' error in Ansible playbook? (GNU/Linux forum at Coderanch)
December 19, 2023 - I have found that conditional expressions can fail in ansible if you're invoking functionality that may not always produce results. That appears to be the case here, where the results of "init_files.results | map(attribute='files') | flatten" must be returning no data rather than an empty collection (which would have a length of 0 for that case).
🌐
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 .
🌐
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....
🌐
Claudia Kuenzler
claudiokuenzler.com › blog › 1063 › ansible-playbook-stat-islnk-error-dict-object-has-no-attribute
Ansible stat.islnk in playbook fails with error: dict object has no attribute islnk
March 24, 2021 - The error was: error while evaluating conditional (resolvconf.stat.islnk == true): 'dict object' has no attribute 'islnk'\n\nThe error appears to be in '/srv/ansible/playbooks/allgemein/ubuntu1804-dns.yaml': line 13, column 3, but may\nbe elsewhere in the file depending on the exact syntax ...
🌐
GitHub
github.com › ansible › ansible › issues › 34219
ansible 'dict object' has no attribute 'stdout_lines' · Issue #34219 · ansible/ansible
December 25, 2017 - The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to have been in '/home/ansible/playbooks/largedir.yml': line 11, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n register: result\n - debug: msg=\"{{ result.stdout }}\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.
Author   ansible
🌐
Devopsroles
devopsroles.com › home › resolve dict object has no attribute error in ansible
Resolve dict object Has No Attribute Error in Ansible - DevopsRoles.com Better 2026
September 16, 2024 - The 'dict object' has no attribute error typically occurs when a playbook tries to access a key or attribute in a dictionary, but that key doesn’t exist or is incorrectly referenced. ... This error signifies that Ansible is attempting to access a key, such as 'email', in a dictionary, but the key isn’t present, leading to the failure of the playbook execution.
🌐
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 - 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
🌐
Google Groups
groups.google.com › g › ansible-project › c › irvn6QeOB_w
'dict object' has no attribute....
The offending line appears to be: - name: Save new iptables - IPv4 ^ here ------------------------------------------------------------------------------- This is the ansible task I have: - name: Save new iptables - IPv4 shell: "{{ iptables_save }} > {{ iptables_v4_rules[ansible_distribution] }}" when: firewall == "iptables" And in my default.yml file I have: iptables_directory: CentOS: "/etc/sysconfig" Rocky: "/etc/sysconfig" Debian: "/etc/iptables" Ubuntu: "/etc/iptables" iptables_v4_rules: 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" ------------------------------------------------------------- I get a similar error when I target CentOS 9.
🌐
Reddit
reddit.com › r/ansible › ansible - template - 'dict object' has no attribute 'stdout_lines'
r/ansible on Reddit: Ansible - Template - 'dict object' has no attribute 'stdout_lines'
September 25, 2018 -

I am using Asible - 2.4.5.0

I am having a problem when trying to insert the results of yum list installed into a template generated file. I am getting the following error:

 'dict object' has no attribute 'stdout_lines'

This is the task

- name: Capture output of currently installed RPMs
  yum:
    list=installed
  register: yum_list_installed
- debug:
   msg: " {{ yum_list_installed }} "
- template:
    src: yumlistinstalled.j2
    dest: /var/tmp/{{backupDir}}/yum_list_installed

This is my template file.

{% for i in yum_list_installed.stdout_lines  %}
{{ i }}
{% endfor %}

The debug output on my screen shows the info with no issue. The problem is when I try to insert that data into my template generated file. Below is sample from output.

TASK [Capture output of currently installed RPMs]

ok: [192.168.100.138] => {
"changed": false,
"failed": false,
"invocation": {
    "module_args": {
        "allow_downgrade": false,
        "conf_file": null,
        "disable_gpg_check": false,
        "disablerepo": null,
        "enablerepo": null,
        "exclude": null,
        "install_repoquery": true,
        "installroot": "/",
        "list": "installed",
        "name": null,
        "security": false,
        "skip_broken": false,
        "state": "installed",
        "update_cache": false,
        "validate_certs": true
    }
},


TASK [debug] 
task path: /root/code/playbooks/someclient/master2.yml:250
ok: [192.168.100.138] => {
"msg": "Hello world!"
}

TASK [template] ******************************************************************************************************************************************
task path: /root/code/playbooks/someclient/master2.yml:252
fatal: [192.168.100.138]: FAILED! => {
"changed": false,
"failed": true,
"msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'stdout_lines'"
}