我通过 URI 模块提取 JSON,并希望将接收到的内容写入文件。我能够获取内容并将其输出到调试器,因此我知道已收到内容,但我不知道写入文件的最佳实践。
来自的重要评论tmoschou https://stackoverflow.com/users/547569/tmoschou:
As of Ansible 2.10, The documentation for ansible.builtin.copy says:
If you need variable interpolation in copied files, use the
ansible.builtin.template module. Using a variable in the content
field will result in unpredictable output.
欲了解更多详情,请参阅this https://github.com/ansible/ansible/issues/50580 and an 解释 https://github.com/ansible/ansible/issues/34595#issuecomment-356091161
原答案:
你可以使用copy
模块,与content
范围:
- copy: content="{{ your_json_feed }}" dest=/path/to/destination/file
这里的文档:复制模块 https://docs.ansible.com/ansible/latest/modules/copy_module.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)