如何将ansible调试日志保存到单个文件

时间:2019-09-02 10:20:16

标签: ansible

要实现的目标-从20台生产服务器上的ansible中检查“ filebeat”和“ Telegraf”服务的状态。万一任何服务在任何服务器上停止,我都会收到警报。

---
- hosts: ALL
  tasks:
   - name: checking service status
     command: systemctl status "{{ item }}"
     with_items:
          - filebeat
          - telegraf
     register: result
     ignore_errors: yes
   - debug:
       var: result

在输出以下-

ok: [10.5.10.10] => {
    "result.results[0].stdout": "* filebeat.service - Filebeat sends log files to Logstash or directly to Elasticsearch.\n   Loaded: loaded (/usr/lib/systemd/system/filebeat.service; disabled; vendor preset: disabled)\n   Active: active (running) since Tue 2019-08-06 11:07:34 IST; 3 weeks 6 days ago\n     Docs: https://www.elastic.co/products/beats/filebeat\n Main PID: 102961 (filebeat)\n   CGroup: /system.slice/filebeat.service\n           `-102961 /usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat\n\nWarning: Journal has been rotated since unit was started. Log output is incomplete or unavailable."
}
ok: [10.5.10.11] => {
    "result.results[0].stdout": "* filebeat.service - Filebeat sends log files to Logstash or directly to Elasticsearch.\n   Loaded: loaded (/usr/lib/systemd/system/filebeat.service; disabled; vendor preset: disabled)\n   Active: inactive (dead)\n     Docs: https://www.elastic.co/products/beats/filebeat"
}

如何将这些输出存储在ansible服务器上的文件中。这样我就可以在任何服务未在任何服务器上运行的情况下发出警报。

1 个答案:

答案 0 :(得分:0)

  1. 为什么其中一个不处于活动状态时不解析输出并看到红色符号?

  2. 回答您的问题: 我要做的是将输出保存到文件中,然后将该文件复制回您的ansible服务器,然后附加所有结果。