# Automate Custome Attribute Population - Vmware

**URL:** <https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668>\
**Category:** Ansible Project\
**Tags:** vmware, ubuntu\
**Created:** [February 22, 2021, 10:41pm UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668 "2021-02-22T22:41:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 22, 2021, 10:41pm UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/1 "2021-02-22T22:41:08Z")

</div>

Hi

Here are my custom attributes

 ![Capture.JPG](https://us1.discourse-cdn.com/ansible/original/2X/3/3c9778edd3d97451b1041a228d5f523f773e5453.jpeg)

Today these are populated with community.vmware.vmware\_guest\_custom\_attributes

But that is manually from the file… it has human error possible

eg Ubuntu 20.04 folks may type Ubuntu20.4

There is facts which ansible gather has the OS info… eg -m setup -a “filter=ansible\_distribution\_version”

Is it somehow possible to get the OS info populated “automatically” with a playbook … ie update the custom attributes dynamically with real time data ?

Any suggestions Please ?

Thanks

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 22, 2021, 10:42pm UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/2 "2021-02-22T22:42:18Z")

</div>

I will give 1 more reason … eg someone upgrade OS from 16.04 to 20.04 … may forget to update the custom attributes…

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [February 23, 2021, 5:29am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/3 "2021-02-23T05:29:50Z")

</div>

You can do this using dynamic inventory and delegate\_to

Here is how -

1. Gather facts about virtual machines

2. Gather facts about custom attributes using vmware\_guest\_info

3. Compare and change if needed

you can see this playbook

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 23, 2021, 6:49am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/4 "2021-02-23T06:49:35Z")

</div>

Thanks a lot Abhijit … i will give it a try & report issue if any.

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 24, 2021, 8:17am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/5 "2021-02-24T08:17:12Z")

</div>

Thanks Abhijit, Awesome , it worked !!!

Only issue is

value: “{{ r.ansible\_facts.ansible\_distribution }}”  
when: vm\_info.instance.customvalues.OS != r.ansible\_facts.ansible\_distribution

that Just give Ubuntu … is it possible to extract the info from setup module ie below part…

“ansible\_lsb”: {  
“codename”: “bionic”,  
**“description”: “Ubuntu 18.04.5 LTS”,**  
“id”: “Ubuntu”,  
“major\_release”: “18”,  
“release”: “18.04”  
},

Hopefully that is also present in CentOS nodes that way … so the description part …

r.ansible\_facts.ansible\_lsb.description ? will do …

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 24, 2021, 8:24am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/6 "2021-02-24T08:24:10Z")

</div>

Wow r.ansible\_facts.ansible\_lsb.description did worked !!! Thanks again Abhijit

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 24, 2021, 10:04am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/7 "2021-02-24T10:04:35Z")

</div>

Setup gives :

“ansible\_distribution”: “Ubuntu”,  
“ansible\_distribution\_file\_parsed”: true,  
“ansible\_distribution\_file\_path”: “/etc/os-release”,  
“ansible\_distribution\_file\_variety”: “Debian”,  
“ansible\_distribution\_major\_version”: “18”,  
“ansible\_distribution\_release”: “bionic”,  
“ansible\_distribution\_version”: “18.04”,

I would like to use OS name as

Ubuntu20.04 & not Ubuntu 20.04.2 LTS

So tried below … as _ **value** _ … all 3 failed … any suggestions Please, on how to concatenate ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 24, 2021, 10:14am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/8 "2021-02-24T10:14:00Z")

</div>

> Setup gives :
> 
> ```
> &quot;ansible\_distribution&quot;: &quot;Ubuntu&quot;,
> &quot;ansible\_distribution\_file\_parsed&quot;: true,
> &quot;ansible\_distribution\_file\_path&quot;: &quot;/etc/os\-release&quot;,
> &quot;ansible\_distribution\_file\_variety&quot;: &quot;Debian&quot;,
> &quot;ansible\_distribution\_major\_version&quot;: &quot;18&quot;,
> &quot;ansible\_distribution\_release&quot;: &quot;bionic&quot;,
> &quot;ansible\_distribution\_version&quot;: &quot;18\.04&quot;,
> 
> ```
> 
> I would like to use OS name as
> 
> Ubuntu20.04 & not Ubuntu 20.04.2 LTS
> 
> So tried below .. as /\*value \*/.. all 3 failed .. any suggestions Please, on how to concatenate ?
> 
> #######################################
> 
> The offending line appears to be:
> 
> ```
> \- name: OS
> value: &quot;\{\{ r\.ansible\_facts\.ansible\_distribution \}\}&quot; &quot;\{\{ r\.ansible\_facts\.ansible\_distribution\_version \}\}&quot;
> ^ here
> 
> ```

This should do the trick:

value: "{{ r.ansible\_facts.ansible\_distribution }} {{ r.ansible\_facts.ansible\_distribution\_version }}"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;racke

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [February 24, 2021, 10:14am UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/9 "2021-02-24T10:14:16Z")

</div>

how about -

“{{ r.ansible\_facts.ansible\_distribution ~ ’ ’ ~ r.ansible\_facts.ansible\_distribution\_version }}”

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 24, 2021, 6:11pm UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/10 "2021-02-24T18:11:22Z")

</div>

“{{ r.ansible\_facts.ansible\_distribution ~ ’ ’ ~ r.ansible\_facts.ansible\_distribution\_version }}” , works

it gives

Ubuntu 18.04

How to get

Ubuntu18.04

Ie remove the space ?

Will try few things … Any docs Please on this ? where you go these … ~ ’ ’ ~ 🙂

BTW yes, “{{ r.ansible\_facts.ansible\_distribution }} {{ r.ansible\_facts.ansible\_distribution\_version }}” , worked too , even that add that space …

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [February 24, 2021, 6:13pm UTC](https://forum.ansible.com/t/automate-custome-attribute-population-vmware/34668/11 "2021-02-24T18:13:22Z")

</div>

Ok this one was easy … just did below

value: “{{ r.ansible\_facts.ansible\_distribution }}{{ r.ansible\_facts.ansible\_distribution\_version }}”

Thanks again Abhi & Stefan Hornburg (Racke)
