On 2/24/21 11:04 AM, Kiran Kumar wrote:
> 
> 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

> We could be wrong, but this one looks like it might be an issue with
> missing quotes. Always quote template expression brackets when they
> start a value. For instance:
> 
>     with_items:
>       - {{ foo }}
> 
> Should be written as:
> 
>     with_items:
>       - "{{ foo }}"
> #######################################
> The offending line appears to be:
> 
>         - name: OS
>           value: "{{ r.ansible_facts.ansible_distribution }}"+"{{ 
> r.ansible_facts.ansible_distribution_version }}"
>                                                              ^ here
> We could be wrong, but this one looks like it might be an issue with
> missing quotes. Always quote template expression brackets when they
> start a value. For instance:
> 
>     with_items:
>       - {{ foo }}
> 
> Should be written as:
> 
>     with_items:
>       - "{{ foo }}"
> 
> #######################################
> {"msg": "template error while templating string: expected token 'end of print 
> statement', got 'r'. String: {{
> r.ansible_facts.ansible_distribution 
> r.ansible_facts.ansible_distribution_version }}"}
> 
> #######################################
> 
> On Wed, Feb 24, 2021 at 12:24 AM Kiran Kumar <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     Wow r.ansible_facts.ansible_lsb.description did worked !!! Thanks again 
> Abhijit
> 
>     On Wed, Feb 24, 2021 at 12:17 AM Kiran Kumar <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>         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 ..
> 
> 
>         On Mon, Feb 22, 2021 at 10:49 PM [email protected] 
> <mailto:[email protected]> <[email protected]
>         <mailto:[email protected]>> wrote:
> 
>             Thanks a lot Abhijit .. i will give it a try  & report issue if 
> any.
> 
>             On Monday, February 22, 2021 at 9:30:23 PM UTC-8 Abhijeet Kasurde 
> wrote:
> 
>                 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
> 
>                 ---
>                 - hosts: running
>                 tasks:
>                 - setup:
>                 register: r
> 
>                 - debug:
>                 msg: "{{ r.ansible_facts.ansible_distribution }}"
> 
>                 - name: Get custom attributes information
>                 vmware_guest_info:
>                 name: CentOS7_Rest
>                 datacenter: Asia-Datacenter1
>                 folder: /Asia-Datacenter1/vm/
>                 register: vm_info
>                 delegate_to: localhost
> 
>                 - debug:
>                 msg: "{{ vm_info }}"
> 
>                 - name: Update OS information
>                 vmware_guest_custom_attributes:
>                 name: CentOS7_Rest
>                 datacenter: Asia-Datacenter1
>                 folder: /Asia-Datacenter1/vm/
>                 state: present
>                 attributes:
>                 - name: OS
>                 value: "{{ r.ansible_facts.ansible_distribution }}"
>                 when: vm_info.instance.customvalues.OS != 
> r.ansible_facts.ansible_distribution
>                 delegate_to: localhost
> 
>                 On Tue, Feb 23, 2021 at 4:12 AM [email protected] 
> <[email protected]> wrote:
> 
>                     I will give 1 more reason .. eg someone upgrade OS from 
> 16.04 to 20.04 .. may forget to update the
>                     custom attributes...
> 
>                     On Monday, February 22, 2021 at 2:41:08 PM UTC-8 
> [email protected] wrote:
> 
>                         Hi
> 
>                         Here are my custom attributes
> 
> 
>                         Capture.JPG
> 
> 
>                         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
> 
>                     -- 
>                     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
>                     [email protected].
>                     To view this discussion on the web visit
>                     
> https://groups.google.com/d/msgid/ansible-project/6a28a2f4-92d4-4963-8a8d-0c79c64b87cbn%40googlegroups.com
>                     
> <https://groups.google.com/d/msgid/ansible-project/6a28a2f4-92d4-4963-8a8d-0c79c64b87cbn%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> 
> 
>                 -- 
>                 Thanks,
>                 Abhijeet Kasurde
> 
>             -- 
>             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
>             [email protected] 
> <mailto:[email protected]>.
>             To view this discussion on the web visit
>             
> https://groups.google.com/d/msgid/ansible-project/653118a7-176e-48c8-921b-f23830da9534n%40googlegroups.com
>             
> <https://groups.google.com/d/msgid/ansible-project/653118a7-176e-48c8-921b-f23830da9534n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> -- 
> 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
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAGhW9Js43VnoQRBUP2XH7%3DTU4JTZ%3DsQdrcXj_OYjv0_k14%3DQ-w%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAGhW9Js43VnoQRBUP2XH7%3DTU4JTZ%3DsQdrcXj_OYjv0_k14%3DQ-w%40mail.gmail.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ab0351a2-6332-a1f3-d93a-0ba29ac40021%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to