Ansible registerで取得した list型の情報に対してkeyを指定して値を取得したい

実現したいこと

Unixコマンドを実行して、実行結果からAAAAAをgrepした結果をcheck_imageという変数でlist型の情報として取得しています。
ここからkeyである AAAAA.BBBBB-CCCCC を指定して値である hoge.co.jp:8080/hoge/image:yyyymmdd-mmssss だけを取得したいです。
AAAAA.BBBBB-CCCCC の文字列にはドット(.)とハイフン(-)が含まれています。
list型の操作方法を調べているのですが、VARIABLE IS NOT DEFINEDや構文エラーとなってしまい値が取得出来ません。
やり方をご存じの方がいらっしゃいましたらご教授頂けないでしょうか。
宜しくお願い致します。

発生している問題・エラーメッセージ

"check_image.AAAAA.BBBBB-CCCCC": "VARIABLE IS NOT DEFINED!"

または

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'jp'. 'dict object' has no attribute 'jp'\n\nThe error appears to be in '/check_image.yml': line ?, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# changed_when: true\n- name: Echo\n ^ here\n"}

該当のソースコード

check_image.yml

1- name: Check image 2 ansible.builtin.shell: hoge command | grep AAAAA 3 register: check_image 4- name: Echo 5 ansible.builtin.debug: 6 var: check_image.stdout_lines.AAAAA.BBBBB-CCCCC

check_image.stdout_linesの中身

1ok: [localhost] => { 2 "check_image.stdout_lines": [ 3 " \"AAAAA.BBBBB-CCCCC\": \"hoge.co.jp:8080/hoge/image:yyyymmdd-mmssss\"," 4 ] 5}

試したこと

変数の型を確認

msg: "{{ check_image.stdout_lines | type_debug }}" "msg": "list"

下記のような形でkeyを指定してもだめでした。

check_image.stdout_lines['AAAAA.BBBBB-CCCCC'] check_image.stdout_lines.AAAAA.BBBBB-CCCCC

下記も試したのですがエラーになりました

msg: "{{ item.value }}" with_items: "{{ check_image.stdout_lines }}"

エラー内容

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'value'. 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'value'\n\nThe error appears to be in '/check_image.yml': line ?, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# changed_when: true\n- name: Echo\n ^ here\n"}

コメントを投稿

0 コメント