Reputation: 17
name: Gather fact for all vm vmware_vm_facts: hostname: "{{ hostname }}" username: "{{ username }}" password: "{{ password }}" validate_certs: no register: vms
name: Gather facts for vm summary vmware_guest_facts: hostname: "{{ hostname }}" username: "{{ username }}" password: "{{ password }}" validate_certs: no datacenter: DC name: "{{ item.guest_name }}" register: gather_facts_for_vm_summary_result loop: "{{ vms.virtual_machines }}" loop_control: label: "{{ item.guest_name }}"
name: Gather facts for vm each properties vmware_guest_facts: hostname: "{{ hostname }}" username: "{{ username }}" password: "{{ password }}" validate_certs: no datacenter: DC name: "{{ item.guest_name }}" schema: vsphere properties: - alarmActionsEnabled - overallStatus - config.name - config.annotation - config.flags - config.managedBy - guest.hostName - guest.net - summary.storage - summary.quickStats - summary.config - summary.runtime - config.memoryAllocation register: gather_facts_for_vm_each_properties loop: "{{ vms.virtual_machines }}" loop_control: label: "{{ item.guest_name }}"
name: Set of combine data set_fact: data: >- {{ data | default([]) + [item.instance | combine(combine_data.instance)] }} vars: combine_data: >- {{ gather_facts_for_vm_each_properties.results | selectattr('instance.config.name','equalto',item['instance']['hw_name']) | list | first }} loop: "{{ gather_facts_for_vm_summary_result.results }}" loop_control: label: "{{ item.instance.hw_name }}"
name: Generate VM inventory report(html) template: src: report_html.j2 dest: vcenter_inventory.html when: export_type == "html"
name: Generate VM inventory report(csv) template: src: report_csv.j2 dest: vcenter_inventory.csv when: export_type == "csv"
[root@junosansible vmware]# pip3 list | grep Jinja2
Jinja2 3.0.1
TASK [Set of combine data] ************************************************************************************************************ fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ gather_facts_for_vm_each_properties.results\n | selectattr('instance.config.name','equalto',item['instance']['hw_name'])\n | list\n | first\n}}'. Error was a <class 'jinja2.exceptions.TemplateRuntimeError'>, original message: no test named 'equalto'"}
PLAY RECAP **************************************************************************************************************************** localhost : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Upvotes: 0
Views: 1386
Reputation: 43
This is answered here: How to solve TemplateRuntimeError: no test named 'equalto' in Ansible?.
Check your Jinja pip version (pip list | grep Jinja2) - it needs to be at least 2.8.
Upvotes: 1