Variable interpolation syntax

11 views
Skip to first unread message

HBach

unread,
Jul 24, 2024, 9:59:29 AM (yesterday) Jul 24
to Ansible Project
Hi, community, 

I’m setting a fact there to grab the JSON dict of the template from the content library.

- name: vm-create | Use the name to identify library item
  set_fact:
    rhel8_9template: "{{ lib_items.value | selectattr('name', 'equalto', 'rhel8-9template')|first }}"

Next, I am using the variable "{{ rhel8_9template.id }}" to feed in the template id to the template_library_item: parameter, part of the overall task.  

- name: vm-create | Create virtual machine from Content Library
  vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
    vcenter_hostname: "{{ hostname }}"
    vcenter_password: "{{ survey_password }}"
    vcenter_validate_certs: false
    name: "{{ survey_vm_name }}"
    library: "{{ library_id }}"
    template_library_item: "{{ rhel8_9template.id }}"

This does work but I want to set a few more facts based on the available operating systems such as rhel9.  I want to set a survey variable to allow admins to choose the OS to deploy.  

I tried two variable syntax structure, neither seem to work.  I need to pull the id from the respective OS. 

template_library_item: "{{ vars['survey_os'].id }}"
template_library_item: "{{ survey_os[.id] }}"

What am I missing here?  Thanks!
Reply all
Reply to author
Forward
0 new messages