Digest.rdfのハッシュ値をansible get_urlに与える方法は?

Digest.rdfのハッシュ値をansible get_urlに与える方法は?

例えばここ要約リストがあります。 get_urlでチェックサム値を生成する簡単な方法があるかどうか疑問に思います。

rdfを辞書に解析する簡単な方法はありますか?それとも、xmlなどのrdfパスを照会できますか?

修正する

私はrdfがいくつかの名前空間を持つxmlであることに気づきました。次のように、Pythonのlxmlなどのプログラミング言語を使用してクエリできます。

from lxml import etree
root = etree.parse("/tmp/digest.rdf")
ns = root.getroot().nsmap
root.xpath('/rdf:RDF/digest:Content[@rdf:about="magick"]/digest:sha256/text()', namespaces=ns)[0]

しかし、ansibleでは動作しません。

  1. 名前空間パラメータを明示的に設定する必要があります。
  2. /text()テキストだけを返すことはできません。これがない場合、返される一致値は辞書リストです。
ansible localhost -m xml -a 'path=/tmp/digest.rdf xpath=/rdf:RDF/digest:Content[@rdf:about="magick"]/digest:sha256/text() print_match=yes' -i inventory
PLAY [Ansible Ad-Hoc] *************************************************************************************************************************************************************************************

TASK [xml] ************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: lxml.etree.XPathEvalError: Undefined namespace prefix
fatal: [localhost]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "<stdin>", line 107, in <module>
      File "<stdin>", line 99, in _ansiballz_main
      File "<stdin>", line 47, in invoke_module
      File "/usr/lib/python3.10/runpy.py", line 224, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_xml_payload_zgisyqdh/ansible_xml_payload.zip/ansible_collections/community/general/plugins/modules/xml.py", line 989, in <module>
      File "/tmp/ansible_xml_payload_zgisyqdh/ansible_xml_payload.zip/ansible_collections/community/general/plugins/modules/xml.py", line 943, in main
      File "/tmp/ansible_xml_payload_zgisyqdh/ansible_xml_payload.zip/ansible_collections/community/general/plugins/modules/xml.py", line 399, in do_print_match
      File "src/lxml/etree.pyx", line 2311, in lxml.etree._ElementTree.xpath
      File "src/lxml/xpath.pxi", line 357, in lxml.etree.XPathDocumentEvaluator.__call__
      File "src/lxml/xpath.pxi", line 225, in lxml.etree._XPathEvaluatorBase._handle_result
    lxml.etree.XPathEvalError: Undefined namespace prefix
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

lxmlのようなnsmapを自動的にインポートする方法はありますか?

ベストアンサー1

おすすめ記事