我使用的命令是:
然而,当我再次这样做时:
它用新文本覆盖旧文本。我想要做的是附加到文件中,而不是替换之前的文本。
我尝试将一个/n添加到原始字符串的末尾,但没有结果。
发布于 2016-06-22 23:26:00
那么lineinfile
模块呢:
local_action:
module: lineinfile
dest: "~/ansible/ansible_log.txt"
line: "The installation failed"
create: yes
local_action:
module: lineinfile
dest: "~/ansible/ansible_log.txt"
line: "Contact me for assistance"
发布于 2022-10-05 21:35:39
尝试了多个帖子,这最终帮助了我想要做的事情。收集各种事实,并最终将其输出到本地文件以供审查。把它发到这里,希望能帮助一些人从安培里开始:)
---
- name: "Collect host OS Version information for the host"
vars:
- output_path: "/tmp"
- filename: "osinfo_{{date}}.csv"
vars_prompt:
- name: input_hostname
prompt: What is the set of hosts you want connect ?
private: no
hosts: "{{ input_hostname }}"
tasks:
- name: CSV Generate output filename
set_fact: date="{{lookup('pipe','date +%Y%m%d_%H%M%S')}}"
run_once: true
- name: CSV - Create file and set the header
local_action: copy content="Hostname,SID,OSVersion,KernelVersion\n" dest="{{output_path}}/{{filename }}"
run_once: true
- name: OS Version info for {{ input_hostname }} hosts
set_fact:
csv_tmp: >
{{ inventory_hostname }},{{SID}},{{ ansible_distribution_version }},{{ ansible_kernel }}
- name: CSV - Write information into .csv file
local_action:
module: lineinfile
dest: "{{output_path}}/{{filename }}"
line: "{{csv_tmp}}"
- name: CSV - Blank lines removal
local_action:
module: lineinfile
dest: "{{output_path}}/{{filename }}"
state: absent
regex: '^\s*$'
https://stackoverflow.com/questions/37976245
复制相似问题