简体   繁体   English

将 Ansible 输出复制到 ini 文件,避免使用分隔符

[英]Copy Ansible output to a ini file with avoiding the delimiters

I got the Ansible output like in the screenshot:我得到了截图中的 Ansible 输出:

Ansible 输出需要复制到属性文件

and I want the output like in the attached file:我想要附加文件中的输出:

需要像下面的截图一样的 ansible 输出

How can I copy the Ansible output to a file in a proper order by eliminating all commas and \\n ?如何通过消除所有逗号和\\n以正确的顺序将 Ansible 输出复制到文件中?

If you want to use the output of ansible, a good way is to use callback plugins .如果你想使用 ansible 的输出,一个好方法是使用回调插件

But in your case, the best way is to simply use ansible to write the content of the variable into the file with copy module :但在您的情况下,最好的方法是简单地使用 ansible 将变量的内容写入带有copy module的文件中:

- name: Write variable content into file
  copy:
    dest: /path/to/the/file.ini
    content: "{{ the_var.content | regex_replace(',', '') }}"
  delegate_to: localhost

The content will be written into the file with interpretation of \\n and the comma removed with the regex_replace filter .内容将被写入文件,解释为\\n并使用regex_replace过滤器删除逗号。

I would suggest to review the previous tasks generating this content to avoid the creation of the commas.我建议查看之前生成此内容的任务,以避免创建逗号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM