-
-
Save gowatana/6791d08b00b96e920c523b8917979a85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Set VM Description-Tags | |
hosts: localhost | |
gather_facts: false | |
collections: | |
- nutanix.ncp | |
module_defaults: | |
group/nutanix.ncp.ntnx: | |
nutanix_host: 'lab-nxce-02.go-lab.jp' | |
nutanix_username: admin | |
nutanix_password: nutanix/4u | |
validate_certs: false | |
vars: | |
target_vm_name: "vm01" | |
vm_desc_tags: | |
env: dev | |
app: web | |
cmdb: id-12345 | |
tasks: | |
- name: Set VM Name | |
set_fact: | |
vm_name: "{{ target_vm_name }}" | |
- name: Output vm_desc_tags (to set) | |
debug: | |
var: vm_desc_tags | |
- name: Convert vm_desc_tags (dict to list) | |
set_fact: | |
tags_list: "{{ tags_list | default([]) + [item.key + '=' + item.value] }}" | |
loop: "{{ vm_desc_tags | dict2items }}" | |
loop_control: | |
loop_var: item | |
- name: Convert vm_desc_tags (list to string) | |
set_fact: | |
tags_string: "{{ tags_list | join(', ') }}" | |
- name: Output vm_desc_tags string (for VM desc) | |
debug: | |
var: tags_string | |
- name: Get VM info by vm_name | |
ntnx_vms_info: | |
filter: | |
vm_name: "{{ vm_name }}" | |
kind: vm | |
register: result | |
ignore_errors: True | |
- name: Get VM UUID | |
set_fact: | |
vm_uuid: "{{ result.response.entities[0].metadata.uuid }}" | |
- name: Output VM Info (Original) | |
debug: | |
var: result.response.entities[0].spec.description | |
- name: Output VM UUID | |
debug: | |
var: vm_uuid | |
- name: Update VM | |
ntnx_vms: | |
vm_uuid: "{{ vm_uuid }}" | |
desc: "{{ tags_string }}" | |
register: result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
Nutanix UVM の Description フィールドを Tag 欄として利用してみる。(Ansible)
https://blog.ntnx.jp/entry/2023/10/31/034114