Ansible:模板化字符串时出现模板错误

时间:2019-04-07 06:57:07

标签: python ansible

在运行以下任务时,它给了我以下错误。我也检查了换行符和其他语法错误,但找不到一个。 是否存在任何兼容性问题,或者我是否犯了任何愚蠢的语法问题?我正在未安装pip(且没有安装权限)的VM上运行此任务

   - name: Move old logs folder
     command: "mv {{ installed_dir }}/logs {{ installed_dir }}/logs_{{ old_version }}"  
     when: "groups['webservice'] | select('search','perfolab') | list"

错误消息:

fatal: [myserver.dm.com]: FAILED! => {"msg": "The conditional check 'groups['webservice'] | select('search','perfolab') | list' failed. The error was: template error while templating string: no filter named 'select'. String: {% if groups['webservice'] | select('search','perfolab') | list %} True {% else %} False {% endif %}\n\nThe error appears to have been in '/home/mylon/ansible-dep/webservice.yml': line 21, column 4, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - name: Move old logs folder\n     ^ here\n"}

Ansible版本-Ansible 2.6.4 python版本= 2.6.6

1 个答案:

答案 0 :(得分:1)

您可能需要selectattr而不选择

http://www.oznetnerd.com/jinja2-selectattr-filter/