Hi
Here are my custom attributes
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
I will give 1 more reason … eg someone upgrade OS from 16.04 to 20.04 … may forget to update the custom attributes…
Akasurde
(Abhijeet Kasurde)
February 23, 2021, 5:29am
3
You can do this using dynamic inventory and delegate_to
Here is how -
Gather facts about virtual machines
Gather facts about custom attributes using vmware_guest_info
Compare and change if needed
you can see this playbook
Thanks a lot Abhijit … i will give it a try & report issue if any.
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 …
Wow r.ansible_facts.ansible_lsb.description did worked !!! Thanks again Abhijit
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 ?
racke
(Stefan Hornburg)
February 24, 2021, 10:14am
8
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 ?
#######################################
The offending line appears to be:
\- name: OS
value: "\{\{ r\.ansible\_facts\.ansible\_distribution \}\}" "\{\{ r\.ansible\_facts\.ansible\_distribution\_version \}\}"
^ here
This should do the trick:
value: "{{ r.ansible_facts.ansible_distribution }} {{ r.ansible_facts.ansible_distribution_version }}"
Regards
racke
Akasurde
(Abhijeet Kasurde)
February 24, 2021, 10:14am
9
how about -
“{{ r.ansible_facts.ansible_distribution ~ ’ ’ ~ r.ansible_facts.ansible_distribution_version }}”
“{{ 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 …
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)