# Playbook error -  ansibleundefinedvariable 'str object' has no attribute 'device\_name'

**URL:** <https://forum.ansible.com/t/playbook-error-ansibleundefinedvariable-str-object-has-no-attribute-device-name/36275>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 2, 2022, 11:22am UTC](https://forum.ansible.com/t/playbook-error-ansibleundefinedvariable-str-object-has-no-attribute-device-name/36275 "2022-02-02T11:22:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivani\_Arora](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Shivani\_Arora](https://forum.ansible.com/u/Shivani_Arora)\
**Post date:** [February 2, 2022, 11:22am UTC](https://forum.ansible.com/t/playbook-error-ansibleundefinedvariable-str-object-has-no-attribute-device-name/36275/1 "2022-02-02T11:22:35Z")

</div>

Hi,

I’m trying to create aws launch template using ansible module - " community.aws.ec2\_launch\_template". I have different types of nodes and want to map different volumes (according to node type) in the launch template.

For Core node - I’m trying to map 2 volumes (sdf and sdh) for which I’m getting below error -

**ansibleundefinedvariable ‘str object’ has no attribute ‘device\_name’**

My code looks like this -

- name: Set ebs volumes

set\_fact:

ebs\_volumes\_list:

- device\_name: **sdf**

ebs:

volume\_size: 10

delete\_on\_termination: yes

encrypted: yes

volume\_type: gp3

- device\_name: **sdh**

ebs:

volume\_size: 10

delete\_on\_termination: yes

encrypted: yes

volume\_type: io1

iops: 500

when: node\_type == “Core”

- name: “Create Node launch template”

community.aws.ec2\_launch\_template:

template\_name: "Test”

monitoring:

enabled: true

state: present

**block\_device\_mappings:**

**- device\_name: “{{ item.device\_name }}”**

**ebs: "{{ item.ebs}}”**

loop: “{{ ebs\_volumes\_list }}”

Ansible version -ansible [core 2.12.1]  
python version = 3.9.9 (main, Jan 5 2022, 11:59:43) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

---

<div class="post-metadata">

**Author:** ![Shivani\_Arora](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Shivani\_Arora](https://forum.ansible.com/u/Shivani_Arora)\
**Post date:** [February 2, 2022, 5:19pm UTC](https://forum.ansible.com/t/playbook-error-ansibleundefinedvariable-str-object-has-no-attribute-device-name/36275/2 "2022-02-02T17:19:42Z")

</div>

Hi All,

Looking for suggestions for above query.

Thanks

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [February 3, 2022, 2:52am UTC](https://forum.ansible.com/t/playbook-error-ansibleundefinedvariable-str-object-has-no-attribute-device-name/36275/3 "2022-02-03T02:52:46Z")

</div>

can you try to debug first and see whats returning

- name: debug  
debug:  
msg: “{{ item[‘device\_name’] }}”  
loop: “{{ ebs\_volumes\_list }}”
