Since the result is produced by a jinja2 statement, the representation is a string. You should still convert to an integer when using the result, ie in a "when condition".
I use something like this to only install a package when there's enough free disk space:
---
- hosts: winhosts
name: Install {{ packagename }}
gather_facts: false
vars:
packagename: name-of-the-package
tempdir: C:\Windows\Temp\{{ packagename }}
required_space: 20
tasks:
- name: execute powershell
win_command: powershell.exe "Get-PSDrive C | Select-Object Free | ConvertTo-Json"
register: getpsdrive
- name: Register freediskspace as a fact
set_fact:
freediskspace: "{{ (getpsdrive.stdout | from_json).Free // 1073741824 }}"
- block:
- name: Create a temporary directory
...
- name: Copy stuff to the temporary directory
...
- name: 'Install {{ packagename }}'
...
- name: 'Remove {{ packagename }} install files'
...
when:
- freediskspace | int > required_space
Bests,
Bram
Op donderdag 14 juli 2016 21:57:16 UTC+2 schreef J Hawkesworth: