Code:
- name: Set category info as fact
set_fact:
category_info: "{{ category_info|default([]) + [ {
'category_name': item | json_query('category_name'),
'category_description': item | json_query('category_description'),
'category_cardinality': item | json_query('category_cardinality'),
'category_associable_types': item | json_query('category_associable_types') | join (',')
} ] }}"
with_items: '{{ tag_category_jsondata.tag_category_info }}'
register: result_tag_category_info
---
- name: Create tag categories from source variables
community.vmware.vmware_category:
validate_certs: false
hostname: "{{ vc_server }}"
username: "{{ vc_user }}"
password: "{{ vc_pass }}"
category_name: '{{ item.category_name }}'
category_description: '{{ item.category_description }}'
category_cardinality: '{{ item.category_cardinality | lower }}'
associable_object_types:
- "{{ item.category_associable_types | split(',') }}"
state: present
delegate_to: localhost
when: item.category_associable_types|length > 0
with_items: '{{ category_info }}'
register: result_import_tag_category
Array:
"category_associable_types": [
"Datastore",
"Opaque Network",
"Storage Pod",
"Virtual App",
"Vmware Distributed Virtual Switch",
"Distributed Virtual Switch",
"Host Network",
"Network",
"Cluster Compute Resource",
"Distributed Virtual Portgroup",
"Folder",
"Host System",
"Resource Pool",
"Virtual Machine",
"Datacenter"
],
Issue:
"associable_object_types": [
"['Datastore', 'Opaque Network', 'Storage Pod', 'Virtual App', 'Vmware Distributed Virtual Switch', 'Distributed Virtual Switch', 'Host Network', 'Network', 'Cluster Compute Resource', 'Distributed Virtual Portgroup', 'Folder', 'Host System', 'Resource Pool', 'Virtual Machine', 'Datacenter']"
],
Ansible seems to complain about what appears to be double brackets as a result of the split adding additional brackets. For the life of me I cannot figure out how to get rid of them. I usually just add [0] to the end of the variable or json_query, but not sure how to remove the brackets ([]) after a split. Any help is appreciated.
UPDATE: Using loop produces same results:
"msg": "value of associable_object_types must be one or more of: All objects, Cluster, Content Library, Datacenter, Datastore, Datastore Cluster, Distributed Port Group, Distributed Switch, Folder, Host, Library item, Network, Host Network, Opaque Network, Resource Pool, vApp, Virtual Machine. Got no match for: Datastore,Opaque Network,Storage Pod,Virtual App,Vmware Distributed Virtual Switch,Distributed Virtual Switch,Host Network,Network,Cluster Compute Resource,Distributed Virtual Portgroup,Folder,Host System,Resource Pool,Virtual Machine,Datacenter",
"invocation": {
"module_args": {
"validate_certs": false,
"hostname": "vcenter-t430.brilliantitsolutions.com",
"username": "[email protected]",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"category_name": "Ansible",
"category_description": "",
"category_cardinality": "single",
"associable_object_types": [
"Datastore,Opaque Network,Storage Pod,Virtual App,Vmware Distributed Virtual Switch,Distributed Virtual Switch,Host Network,Network,Cluster Compute Resource,Distributed Virtual Portgroup,Folder,Host System,Resource Pool,Virtual Machine,Datacenter"
],
EFFECTIVELY, I need this:
- name: Create tag categories from source variables
community.vmware.vmware_category:
validate_certs: false
hostname: "{{ vc_server }}"
username: "{{ vc_user }}"
password: "{{ vc_pass }}"
category_name: '{{ item.category_name }}'
category_description: '{{ item.category_description }}'
category_cardinality: '{{ item.category_cardinality | lower }}'
associable_object_types:
- Datastore
- Opaque Network
- Storage Pod
- Virtual App
- Vmware Distributed Virtual Switch
- Distributed Virtual Switch
- Host Network
- Network
- Cluster Compute Resource
- Distributed Virtual Portgroup
- Folder
- Host System
- Resource Pool
- Virtual Machine
- Datacenter
state: present