ansible
STDOUTとPlaybookでrow_count値のみを取得し、row_countが10より大きい場合に失敗する方法はありますか?
(行数> 10)
標準出力:
temp_id,order_id,status,created_at
854556545610443,,order_success,2022-08-23 09:29:29
854556545610444,,order_success,2022-08-23 09:37:02
854556545610445,,order_success,2022-08-23 09:38:47
854556545610446,,order_success,2022-08-23 12:40:41
854556545610447,,order_success,2022-08-24 07:53:54
854556545610448,,order_success,2022-08-24 10:11:48
854556545610449,,order_success,2022-08-24 14:34:37
854556545610450,,order_success,2022-08-24 23:49:52
854556545611146,,order_success,2022-09-16 12:55:57
854556545611147,,order_success,2022-09-16 12:56:00
854556545611148,,order_success,2022-09-16 12:56:07
854556545611149,,order_success,2022-09-16 12:56:07
854556545611150,,order_success,2022-09-16 12:56:10
13 row(s) has been generated successfully.
行数 = 13
答え1
近い標準出力属性として登録されている変数にも属性があります。標準出力ライン。たとえば(テストのために簡略化)
out:
stdout_lines:
- line_01
- line_02
- line_03
- 3 row(s) has been generated successfully.
- row_count = 3
変数を宣言します。最後の行を取得して値を分割します。
row_count: "{{ out.stdout_lines|last|split('=')|last|int }}"
与えられた
row_count: '3'
テスト行数
- assert:
that: row_count|int < 3
fail_msg: "[ERR] More than 2 rows. row_count={{ row_count }}"
テストのための完全なプレイブックの例
- hosts: localhost
vars:
out:
stdout_lines:
- line_01
- line_02
- line_03
- 3 row(s) has been generated successfully.
- row_count = 3
row_count: "{{ out.stdout_lines|last|split('=')|last|int }}"
tasks:
- debug:
var: row_count
- assert:
that: row_count|int < 3
fail_msg: "[ERR] More than 2 rows. row_count={{ row_count }}"