2017-08-17 3 views
3

Imは、when文に使用している指定された文字列の出力変数を検索できません。以下のコードは、出力変数の文字列 "distribute-list"をチェックするはずですが、プレイブックを実行するとエラーになります。ここで出力レジスタの文字列を一致させるための条件付きの使用(可能)

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"} 

が問題を引き起こしているコードです:

- ios_command: 
    commands: show run | sec ospf 
    provider: "{{cli}}" 
    register: output 
- debug: 
    msg: "{{output.stdout_lines}}" 
    when: output | search("distribute-list")       

は、いくつかの助けをお願い申し上げます。前もって感謝します。

答えて

4

searchは文字列を入力としますが、outputは異なるプロパティを持つ辞書です。

あなたはios -familyモジュールstdoutのために文字列のリストであり、通常のcommandモジュールのstdoutであるのに対しstdout_linesは(リストのリストであるので、joinここで中間必要

when: output.stdout | join('') | search('distribute-list') 

と良いことがあります文字列とstdout_linesは文字列のリストです)。

+0

ありがとうございます。別のフォーラムでこれを掲示し、助けを得ることができませんでした。 Stack Overflowで掲示され、1時間以内に私は助けを得る。どうもありがとう – techkid

関連する問題