Update custom attribute called OS

61 views
Skip to first unread message

esxi...@gmail.com

unread,
Feb 7, 2021, 12:03:34 AM2/7/21
to Ansible Project
Hi

anyone can suggest Please if we can update the say a 'custom attribute' called OS from OS level with below


Say i want to use Windows 2019 DataCenter .. which is not aviable btw in vCenter 6.7 .. so getting that as ansible facts and add to attributes somehow

Thanks

Dick Visser

unread,
Feb 7, 2021, 1:46:52 AM2/7/21
to ansible...@googlegroups.com
You could override the values by combining it with a specially crafter
dictionary, or loop over it, etc.
How exactly you do this depends on the data structure, but the module
documentation does not mention any such custom attributes.
If you have an example of your playbook and the resulting data structure?
> --
> 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/161ffe5a-656f-4ea9-8d7d-e7518b7e3936n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

esxi...@gmail.com

unread,
Feb 7, 2021, 3:58:26 AM2/7/21
to Ansible Project
Thanks for Reply, just to give you more context

The custom attributes i have added are


OS
Application
Owner

Etc...

Now why OS ? That is as the OS seen by vCenter is say Ubuntu .,... but it does not tell if that is Ubuntu18.04 or Ubuntu20.04 ... so i have added them manually for now.. but looking for way to Automate that.

Thanks

Dick Visser

unread,
Feb 7, 2021, 7:55:31 AM2/7/21
to ansible...@googlegroups.com
That's not really an example of the actual data structure. So for the moment the answer is that what you want should be possible. 


--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Abhijeet Kasurde

unread,
Feb 7, 2021, 11:26:00 PM2/7/21
to ansible...@googlegroups.com
Hi

You can set and get custom values like

  - name: Set Custom Attributes
    community.vmware.vmware_guest_custom_attributes:
      validate_certs: False
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      state: present
      name: 'dev-1'
      attributes:
        - name: OS
          value: 'Windows Server 2019'

  - name: Get guest information
    community.vmware.vmware_guest_info:
      validate_certs: False
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      name: 'dev-1'
      datacenter: Asia-Datacenter1


The output will be like -

ok: [localhost] => {
    "changed": false,
    "instance": {
        "annotation": "",
        "current_snapshot": null,
        "customvalues": {
            "OS": "Windows Server 2019"
        },
...



--
Thanks,
Abhijeet Kasurde

esxi...@gmail.com

unread,
Feb 8, 2021, 6:46:51 PM2/8/21
to Ansible Project
Thanks for Reply Abhijit .. i already saw ur module - community.vmware.vmware_guest_custom_attributes 

I am doing this already which powershell  with one liner

Get-VM $($line.name) |Set-Annotation -CustomAttribute "OS" -Value $($line.os)


The power of ansible is it can talk on OS level & Vmware powercli does only on vCenter level

vCenter sees OS os with Vmwre-tools as CentOS7 .. ok gr8 .. but when it comes to say Ubuntu it simply says Ubuntu 64 bit & not Ubuntu18

Now we know with Ansible "fatcs & filter"  we can get OS details ... so that can somehow read & push into custom attributes ? If yes that will be awesome.

ansible all -m setup -a "filter=ansible_distribution_version" -o

Thanks

esxi...@gmail.com

unread,
Feb 10, 2021, 12:39:35 AM2/10/21
to Ansible Project
So again experts & it could be a feature request ...


## How can we dynamicailly update OS custome attribute

  - name: Set Custom Attributes
    community.vmware.vmware_guest_custom_attributes:
      validate_certs: False
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      state: present
      name: 'dev-1'
      attributes:
        - name: OS
          value: 'Windows Server 2019'
         
         
ansible all -m setup -a "filter=ansible_distribution_version" -o =====>> can be used as "value" in above ?

Dick Visser

unread,
Feb 10, 2021, 2:54:27 AM2/10/21
to ansible...@googlegroups.com
Can you be more clear in what you are actually trying to achieve?
What problem are you exactly having?
Share a playbook or inventory that does not do what you want, for example. 


Reply all
Reply to author
Forward
0 new messages