シェルパイプラインを実行するAnipalスクリプトを作成しようとしていて、そのパイプラインの出力に基づいてプレイブックの実行を終了するかどうかを決定しています。ここで可能性のあるシェルコマンドの出力を確認する
- name: Check if the number of HITACHI devices is equal to 1
shell: lsscsi | grep HITACHI | awk '{print $6}' | wc -l
register: numOfDevices
when: numOfDevices|int == 1
エラーされています:
{
"failed":true,
"msg":"The conditional check 'numOfDevices|int == 1' failed.
The error was: error while evaluating conditional (numOfDevices|int == 1): 'numOfDevices' is undefined\n\nThe error appears to have been in '/etc/ansible/config/test.yml': line 14, 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 - name: Check if the number of HITACHI devices is equal to 1\n ^here\n"
}
ことができる人は問題になる可能性がものを私に伝えます
ここで、問題のコードはありますか?
'grep | awk | wc'?あなたはawkが3つのコマンドのすべての仕事をすることができると思いますか? –
ところで、あなたの実際の目標は何ですか?正確にHitachiデバイスが1つでもない場合、プレイブックの実行を停止しますか?正確に1台のHitachiデバイスが存在する(またはそうでない)場合、他のコマンドを実行しますか?他に何か? 'when'節は、どこにあるのか分からない。問題はそれがどこにあるべきかということです。 –
正確に1台のHitachiデバイスがない場合は、プレイブックを停止したいと考えています。 – Omri