Playbook error - ansibleundefinedvariable 'str object' has no attribute 'device_name'

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)]

Hi All,

Looking for suggestions for above query.

Thanks

can you try to debug first and see whats returning

  • name: debug
    debug:
    msg: “{{ item[‘device_name’] }}”
    loop: “{{ ebs_volumes_list }}”