Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible语法,用于验证安装的最低.net版本_.net_Ansible_Jinja2_Powershell Remoting - Fatal编程技术网

Ansible语法,用于验证安装的最低.net版本

Ansible语法,用于验证安装的最低.net版本,.net,ansible,jinja2,powershell-remoting,.net,Ansible,Jinja2,Powershell Remoting,我使用以下语法验证远程windows服务器上的最低.net版本: - name: Check for current Microsoft .NET Framework 4 version win_reg_stat: path: HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full name: Version register: dotnet_version failed_when: "dotnet_

我使用以下语法验证远程windows服务器上的最低.net版本:

- name: Check for current Microsoft .NET Framework 4 version
  win_reg_stat:
    path: HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
    name: Version
  register: dotnet_version
  failed_when: "dotnet_version.value | trim | int | < {{ min_dotnet_version }}"
  changed_when: "dotnet_version.value | trim | int | > {{ min_dotnet_version }}"
- debug: var=dotnet_version.value
变量:

var_min_dotnet_version: 394802
当我尝试使用以下语法时:

- name: Check for current Microsoft .NET Framework 4 version
  win_reg_stat:
    path: HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
    name: Version
  register: dotnet_version
  failed_when: dotnet_version.value is version({{ min_dotnet_version }}, operator='<', strict=True)
  changed_when: dotnet_version.value is version({{ min_dotnet_version }}, operator='>=', strict=True)
- debug: var=dotnet_version.value

感谢您的建议和见解。

它(正确地)抱怨您的when语句中的
{{
,因为它们是不必要的——同样的原因,您不必在
中添加
dotnet\u version.value
{{
--整个when隐含在一个jinja2上下文中。你的问题中有很多混乱;从
win\u reg\u stat
返回的
dotnet\u版本
的实际内容是什么?我没有意识到这种复杂性。移除大括号是有效的。这应该在中得到清楚的解释,尽管我承认你可以很容易地在ansible文档中选择您的方式,它清楚地解释了:以及
- name: Check for current Microsoft .NET Framework 4 version
  win_reg_stat:
    path: HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
    name: Version
  register: dotnet_version
  failed_when: dotnet_version.value is version({{ min_dotnet_version }}, operator='<', strict=True)
  changed_when: dotnet_version.value is version({{ min_dotnet_version }}, operator='>=', strict=True)
- debug: var=dotnet_version.value
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: dotnet_version.value is version({{ min_dotnet_version }}, operator='>=', strict=False)
fatal: [fqdn]: FAILED! => {"msg": "The conditional check 'dotnet_version.value is version({{ min_dotnet_version }}, operator='>=', strict=False)' failed. The error was: Version comparison: float object has no element 2"}
var_min_dotnet_version: '4.6.2'