【问题标题】:Ansible logstash installationAnsible Logstash 安装
【发布时间】:2020-02-28 22:46:26
【问题描述】:

我正在尝试在 RHEL 7 上使用 Ansible 安装 Logstash。
安装后,我无法启动 logstash 服务。我得到service not found 错误。我在网上搜索并找到了以下命令。

/usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd

之后,logstash 服务启动。

我在 systemd 命令上方的剧本中做了如下操作。但它不是幂等的。每次都在运行第一个任务。 我有两个问题。
1. 除了使用shell,还有什么方法可以实现吗?
2.我可以在这个任务中放入什么when条件使其具有幂等性。如果我检查服务状态并将状态置于何时状态,那么我需要在最后再次写入以确保状态(重复任务)。 否则我只需要在第一次在此服务器上运行此命令时运行它。那可能吗? 请指教。

    - name: generate logstash.service file for systemd
      shell: /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd

    - name: Enable and restart logstash.service
      systemd:
       name: logstash.service
       enabled: yes
       state: restarted

【问题讨论】:

    标签: ansible logstash


    【解决方案1】:
    1. 如果你想执行一些脚本 - 你可以使用shell 或command。否则你可以自己生成systemd服务

    2. 您不需要使用when 来执行此操作,您可以在shell 任务中使用creates 关键字。

    假设您的单元文件是在 /etc/systemd/system/logstash.service 中创建的

    你应该把你的第一个任务写成

     - name: generate logstash.service file for systemd
       shell: /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd
       creates: /etc/systemd/system/logstash.service
    

    如果ansible下次发现这个文件存在-它不会再次运行脚本。

    另一种方法是模板化 /etc/logstash/startup.options 并仅在您的模板已更改时运行生成服务任务。

    【讨论】:

    • 是否有任何用于 /usr/share/logstash/bin/system-install 而不是使用 shell 命令的 ansible 模块
    • @smily 我不这么认为。如果您尝试使用 ansible 部署 ELK 堆栈 - 您可能需要检查 Ansible Galaxy 的现有角色,galaxy.ansible.com/…
    • 谢谢,是的,我最初使用了这个角色。但是服务没有启动,我不得不用这个解决方法更新代码
    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 2013-08-16
    相关资源
    最近更新 更多