2017-07-19 8 views
-1

私は束(100+)のCisco Catalystスイッチを押して、特定のラインカードがインストールされているかどうかを確認するためにAnatileを使用しようとしています。 SSH経由で、これは "sh mod"コマンドで行うことができます。プレイブックでそのコマンドの出力を解析し、特定の文字列が一致する場合はコマンドの出力を表示したいと思います。文字列の一致する可能性のある出力IOS出力

fatal: [redacted-hostname]: FAILED! => {"failed": true, "msg": "The conditional check 'showmod | search(\"4548\")' failed. The error was: Unexpected templating type error occurred on ({% if showmod | search(\"4548\") %} True {% else %} False {% endif %}): expected string or buffer\n\nThe error appears to have been in '/etc/ansible/playbooks/linecard-4548.yaml': line 22, 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: \"msg='4548 Card Found'\"\n ^here\n"}

現在脚本コード:

--- 
- hosts: redacted-hostname 
    gather_facts: yes 
    connection: local 

    tasks: 

    - name: SYS | Define provider 
    set_fact: 
     provider: 
     host: "{{ inventory_hostname }}" 
     username: redacted-user 
     password: redacted-password 

    - name: IOS | Get Module List 
    ios_command: 
     provider: "{{ provider }}" 
     commands: 
      - sh mod | inc 4548 
    register: showmod 

    - debug: "msg='4548 Card Found'" 
    when: showmod.stdout | search("/4548/") 

は私がして無駄にすることなく、.stdoutデバッグでwhenを試みた今、以下の脚本で、私は次のエラーを取得します。私はいくつかの研究を行いましたが、通常は私の場合はshowmodが定義されていない間違いが発生していますが、それは間違いありません。私が次のスニペットでデバッグを置き換えた場合、プレイブックはうまく動作しますが、もちろん、私が望むものではないすべてのスイッチの出力を印刷します。

- name: IOS | Show Output 
    debug: 
     var: showmod 

お勧めはありますか?

答えて

1

ios_command戻るリストのリストとしてリストとしてstdoutstdout_linescommandモジュール列としてリターンstdout及びリストとしてstdout_lines一方)。

だからあなたの場合には、あなたが試してみたいことがあります。

- debug: "msg='4548 Card Found'" 
    when: showmod.stdout | join(" ") | search("/4548/") 
+0

それをやった、ありがとうございました! – Ross

関連する問題