実現したいこと
検索対象のメッセージ一覧にダブルクォーテーションとコロンが含まれています。
ダブルクォーテーションとコロンが含まれていることによってSyntax Errorとなります。
それぞれをエスケープしてみたのですがエラーが解消しません。
改善方法をご存知の方がいらっしゃいましたらご教授頂けないでしょうか。
宜しくお願い致します。
発生している問題・エラーメッセージ
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 1 (char 0) Syntax Error while loading YAML. mapping values are not allowed in this context The error appears to be in '/test.yml': line ?? column ?? but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: msg: "Service is stopped" when: chk_hoge | select("regex", ""SubState": "running"") | list | length != 1
該当のソースコード
test.yml
1--- 2- name: Check service 3 ansible.builtin.systemd: 4 name: "hoge.service" 5 register: chk_status 6- name: Check result 7 ansible.builtin.debug: 8 var: chk_status 9- name: Echo 10 ansible.builtin.debug: 11 msg: "Service is stopped" 12 when: chk_status | select("regex", ""SubState": "running"") | list | length != 1
chk_statusの結果抜粋
1ok: [localhost] => { 2 "chk_status": { 3 "ansible_facts": { 4 "discovered_interpreter_python": "/usr/bin/python" 5 }, 6 "changed": false, 7 "failed": false, 8 ・ 9 ・ 10 "name": "hoge.service", 11 "status": { 12 "SubState": "dead", 13 ・ 14 ・
試したこと
下記のように該当の条件分でダブルクォーテーションとコロンをエスケープしたのですがエラーが解消しません。
when: chk_status | select("regex", "\"SubState\"\: \"running\"") | list | length != 1 when: chk_status | select("regex", "{% raw %}"SubState": "running"{% endraw %}") | list | length != 1

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2023/05/13 09:06