如何解决xml文件与Ansible中的python脚本之间的交互
当前,我有一个剧本,它创建一个.xml文件,一个python脚本接收.xml文件并对其进行处理。我打算使用j2模板以 {{ansible_date_time.iso8601_basic_short}}。xml 的形式创建文件,以便跟踪新文件。但是,由于路径在shell命令和python脚本中进行了硬编码,因此该剧本目前确实是静态的。
有什么建议吗?
---
- name: testing
hosts: localhost
tasks:
- name: execute some shell command that produces an xml output file in current dir
shell: XXX
- name: Takes in xml output file produced earlier and passes into script.py
script: python_script.py
解决方法
如果我理解您的要求,为什么不使用在stdout上打印XML内容的shell脚本,以便您可以将其注册到变量中并在variable.stdout之后使用它? 喜欢:
- name: generate xml
shell:
echo '<xml></xml>'
register: myxml
- name: create xml file
copy:
content: "{{ myxml.stdout }}"
dest: "{{ ansible_date_time.iso8601_basic_short }}.xml"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。