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

588 views
Skip to first unread message

Shivani Arora

unread,
Feb 2, 2022, 6:22:35 AM2/2/22
to Ansible Project
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)]



Shivani Arora

unread,
Feb 2, 2022, 12:19:42 PM2/2/22
to Ansible Project
Hi All,

Looking for suggestions for above query.

Thanks

Rajthecomputerguy

unread,
Feb 2, 2022, 9:53:09 PM2/2/22
to ansible...@googlegroups.com
can you try to debug first and see whats returning 

      - name: debug
        debug:
          msg: "{{ item['device_name'] }}"
        loop: "{{ ebs_volumes_list }}"

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/56cb91d7-5d54-4c18-9328-85ecccf28659n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages