invalid syntax on datastore check

4 views
Skip to first unread message

bilel....@gmail.com

unread,
Feb 16, 2023, 5:22:08 PM2/16/23
to Ansible Project

I'm trying to create a playbook to verifie a space on the datastore before create a VM and I need the creation to faild if datastore usage > 80 % 

My playbook is like the below  and I am stuck on The conditional check  invalid syntax   

Can you please help 

    - name: Get VM datastore info
      vmware_datastore_facts:
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user }}"
        password: "{{ vcenter_pass }}"
        datacenter: "{{data_center}}"
        validate_certs: False
        name: "{{ vm_datastore }}"
      register: datastore
      delegate_to: localhost

    - set_fact:
        datastore_capacity: "{{ datastore.datastores[0].capacity }}"
        datastore_freeSpace: "{{ datastore.datastores[0].freeSpace}}"
       
    - fail:
        msg: "No more space on VMware datastore"
      when:
        -  ' ("{{datastore_freeSpace}}" // "{{datastore_capacity}}")  * 100) > 80'

Dick Visser

unread,
Feb 17, 2023, 12:24:24 AM2/17/23
to ansible...@googlegroups.com
Try:

      when: (datastore_freeSpace // datastore_capacity * 100) > 80


--
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/a89f4431-2ba1-4b42-98b3-83f650e2ea3cn%40googlegroups.com.
--
Sent from Gmail Mobile
Reply all
Reply to author
Forward
0 new messages