ansible - 将列表保存到ansible中的文件列
问题描述
我创建了可以使用某些扩展名中的文件列表更新纯文本 CSV 文件(报告)的代码:
- name: Find files with extension {{ extensions }} in paths {{ paths }}
find:
paths: "{{ path }}"
recurse: yes
patterns: "{{ extensions }}"
file_type: file
register: files_matched
changed_when: false
- name: Show files paths
debug:
msg: "{{ files_matched.files | map(attribute='path') | list }}"
register: files
输出正在文件中注册:
- name: Save outputs from hosts
become: false
lineinfile:
dest: "{{ hostvars['localhost'].base_dir }}/files_to_remove.csv"
line: "{{ inventory_hostname }};{{ server_env }};{{ path }};{{ files_matched.files | map(attribute='path') | list }}"
insertafter: EOF
delegate_to: localhost
changed_when: false
保存在文件中的输出如下:
server001;PRD;/root;[u'/root/Agent-Core-RedHat_EL7-11.0.0-326.x86_64.rpm', u'/root/Agent-Core-RedHat_x86_64.rpm', u'/root/Agent-Core.rpm', u'/root/some_file.tar']
也许解决方案很简单,但我无法更新行/行以生成 CSV 报告,该报告可以轻松导入 Excel 以获得如下内容:
server1 | PRD | /root | /root/Agent-Core-RedHat_EL7-11.0.0-326.x86_64.rpm |
| | | /root/Agent-Core-RedHat_x86_64.rpm |
| | | /root/some_file.tar |
--------+-----+-------+---------------------------------------------------+
server2 | PRD | /root | /root/1.rpm |
| | | /root/some_file.rpm |
| | | /root/some_file.tar |
...我花了一天时间寻找解决方案,但我可能不明白一些事情。可以按照上述格式进行吗?我不知道如何才能拥有这样的 CSV。
解决方案
推荐阅读
- python - pandas to_excel() 忽略/允许重复的列名
- xml - “构建”一个整理所有 XInclude 的 XML 文件
- c++ - 前向声明与包含在 Google c++ 样式指南中
- angular - 在 Angular 2/4 中使用 http.get() 进行递归调用
- qt - 在 QTabWidget 中添加图表
- vba - 代码检查/帮助
- jquery - 使用 cookie 中的值来修改页面内容 - Google 跟踪代码管理器
- java - 引起:com.fasterxml.jackson.core.JsonParseException:意外字符('''(代码 39)):
- c# - WPF - 控制可见性 - 更好地使用绑定?
- java - '$HADOOP_HOME/bin/hadoop version' 工作正常,但 'hadoop version' 不起作用