実現したいこと
①の処理で実行したコマンド結果(command1_result.stdout)で、"stdout_lines"キーに"hoge.repo"の文字列が含まれている場合、②でcommand2を実行したい
色々と試しているのですがエラーが解消しません。
何かお気づきことがありましたらご教授頂けないでしょうか。
宜しくお願い致します。
発生している問題・エラーメッセージ
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'command1_result.stdout | selectattr(\"stdout_lines\", \"contains\", \"hoge.repo\") | list | length == 0' failed. The error was: error while evaluating conditional (command1_result.stdout | selectattr(\"stdout_lines\", \"contains\", \"hoge.repo\") | list | length == 0): 'str object' has no attribute 'stdout_lines'. 'str object' has no attribute 'stdout_lines'\n\nThe error appears to be in '/test.yml': line 22, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n var: command1_result\n- name: execution command2\n ^ here\n"}
該当のソースコード
test.yml抜粋
1# ① 2- name: activate package repo 3 ansible.builtin.command: command1 4 register: command1_result 5 6# ② 7- name: execution command2 8 ansible.builtin.command: command2 9 when: command1_result.stdout | selectattr("stdout_lines", "contains", "hoge.repo") | list | length == 0
command1_result.stdoutの抜粋
1 "stdout_lines": [ 2 "This is test repo", 3 "adding repo from: http://www.hoge.co.jp:8080/hoge.repo", 4 "repo saved to /etc/yum.repos.d/hoge.repo" 5 ]
試したこと
下記を試しましたが同様のエラーなります
selectattr("stdout_lines", "match", "hoge.repo")
selectattr("stdout_lines", "eq", "hoge.repo")
下記の行をコメントアウトした場合、エラーは解消されます。
when: command1_result.stdout | selectattr("stdout_lines", "contains", "hoge.repo") | list | length == 0

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/24 10:46