1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- ---
- # Create VM(s) on Nutanix
- - name: Store VM template contents
- set_fact:
- vm_body: "{{ lookup('template', 'vm-body.yml.j2') | from_yaml }}"
- loop: "{{ ntx_vm_defs }}"
- register: templates
- loop_control:
- loop_var: vm
- - name: Debug | Print Template for VM(s)
- debug:
- msg: "{{ item.ansible_facts.vm_body }}"
- when: global_debug|bool
- with_items: "{{ templates.results }}"
- - name: Create VM(s) from template
- uri:
- url: "{{ pc_api_url }}/vms"
- body:
- "{{ template.ansible_facts.vm_body }}"
- method: POST
- validate_certs: no
- body_format: json
- headers:
- Cookie: "{{ pc_session_cookie }}"
- status_code: 202
- register: json_create_result
- with_items: "{{ templates.results }}"
- loop_control:
- loop_var: template
- - name: Debug | Print VM(s) creation result
- debug:
- msg: "VM(s) created : {{ json_create_result }}"
- when: global_debug|bool
- - name: Store created VM(s) UUID(s)
- set_fact:
- vm_uuids: "{{ vm_uuids|default([]) + [ item.json.metadata.uuid ] }}"
- with_items: "{{ json_create_result.results }}"
-
- - name: Debug | Print VM(s) UUID(s)
- debug:
- msg: "Created VM(s) UUID(s) : {{ vm_uuids }}"
- when: global_debug|bool
|