特定のコマンドの出力に表示されると予想される文字列のリストがあります。タスクをテストして(1つ以上の項目が含まれていない場合)、実行するためのansibleスクリプトをどのように生成できますか?
したがって、私のansibleスクリプトは次のようになります。
vars:
musthave:
- value1
- value2
tasks:
- name: Check the configured values
command: "cat configfile"
register: current_configuration
changed_when: false
- set a variable if one or more of the musthave's are missing in current_configuration.stdout
...
- name: Execute task to reconfigure system
command: "reconfigure..."
when: true = variable
では、似たようなものもありますか?
variable = false
for s in musthave:
if not s in current_configuration.stdout:
variable |= true
ベストアンサー1
この問題を解決するために中間変数は必要ありません。 ~によるとアンサーブル文書、difference
フィルタ選択に必要な値のリストと設定ファイルの出力の違い。
可変的な: 必需品: - 値1 - 値2 仕事: - 名前:設定値の確認 コマンド: "seq -f '値%g' 2 1 5" 登録:現在の設定 変更時間:偽 - デバッグ: var=current_configuration.stdout_lines - 名前: システムの再構成操作を実行します。 デバッグ: msg="{{必ずなければなりません|違い(current_configuration.stdout_lines)}}" タイミング:必須の違い(current-config.stdout_lines)
debug
最後の操作は、差が空でない場合にのみ実行されます。