小编tec*_*kid的帖子

使用条件匹配输出寄存器中的字符串(Ansible)

我无法在输出变量中搜索我用于when语句的指定字符串.下面的代码应该检查输出变量中的字符串"distribute-list",但是当运行playbook时它会给出错误.

fatal: [192.168.3.252]: FAILED! => {"failed": true, "msg": "The conditional check 'output | search(\"distribute-list\")' failed. The error was: Unexpected templating type error occurred on ({% if output | search(\"distribute-list\") %} True {% else %} False {% endif %}): expected string or buffer\n\nThe error appears to have been in '/home/khibiny/test4.yml': line 26, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - debug:\n    ^ here\n"}
Run Code Online (Sandbox Code Playgroud)

以下是导致问题的代码:

 - ios_command:
     commands: show run …
Run Code Online (Sandbox Code Playgroud)

yaml ansible

4
推荐指数
1
解决办法
7405
查看次数

如果其他在 ansible 打印语句中

我想要一些有关具有多个条件的打印语句的语法的帮助。目前, for 的引号'{{inventory_hostname}}'导致错误,如果我删除引号,剧本会运行但会列出文本 inventory_hostname 而不是变量。我想知道如何打印变量,以及 if else 语句中的语法是否正确。

- debug:
    msg: "{{ 'LTE status on '{{inventory_hostname}}'  is good to go!' if output.stdout | join('') is search('Selected = LTE') else  'LTE status on '{{inventory_hostname}}'  is not operational!' }}"
Run Code Online (Sandbox Code Playgroud)

conditional ansible

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

ansible ×2

conditional ×1

yaml ×1