ansible - Ansible playbook 检查服务是否启动 - 安装一些东西
问题描述
我需要在我的 linux 系统上安装 Symantec 端点安全,并且我正在尝试编写一个剧本来这样做
当我想安装程序时,我使用 ./install.sh -i 但是在安装之后,当我再次运行安装时,我得到了这个消息:
root@TestKubuntu:/usr/SEP# ./install.sh -i
Starting to install Symantec Endpoint Protection for Linux
Downgrade is not supported. Please make sure the target version is newer than the original one.
这就是我在剧本中安装它的方式
- name: Install_SEP
command: bash /usr/SEP/install.sh -i
我想是否可以检查服务是否已启动,如果没有服务则安装它,或者可能有更好的方法来执行此操作。
非常感谢您的宝贵时间
解决方案
问:“我想检查服务是否启动,如果没有服务则安装它。”
可以使用service_facts。例如检查服务是否正在运行
vars:
my_service: "<name-of-my-service>"
tasks:
- name: Collect service facts
service_facts:
- name: Install service when not running
command: "<install-service>"
when: "my_service not in ansible_facts.services|
dict2items|
json_query('[?value.state == `running`].key')"
要检查已安装的服务,请使用
json_query('[].key') }}"
(未测试)
推荐阅读
- python - 我使用 scipy 的 python 代码抛出了一个值错误
- javascript - 从 JSON 获取 D3 的日期
- amazon-s3 - SSE-KMS 和 SSE-C 的区别
- python - 如何从嵌套字典中按值获取字典键?
- javascript - Angular - 如何使用 API 显示元素并使用复选框进行排序
- seo - 使用动态 slug 时,服务器端渲染如何在 Nuxt 上工作?
- c++ - 如何用矩形制作 2 点角并保持正确的厚度?
- database - 建模多个子表数据库的最佳方法
- flutter - 容器类中的约束结构
- java - Java将位置添加到具有有限位置的数组