Ansible playbook检查服务是否启动,如果没有-安装一些东西

Ansible playbook检查服务是否启动,如果没有-安装一些东西,ansible,ansible-inventory,Ansible,Ansible Inventory,我需要在我的linux系统上安装Symantec endpoint security,我正试图编写一本剧本来实现这一点 当我想安装我使用的程序时。/install.sh-i 但是在安装之后,当我再次运行安装时,我得到以下消息: root@TestKubuntu:/usr/SEP# ./install.sh -i Starting to install Symantec Endpoint Protection for Linux Downgrade is not supported. Please

我需要在我的linux系统上安装Symantec endpoint security,我正试图编写一本剧本来实现这一点

当我想安装我使用的程序时。/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
我想如果有可能检查服务是否启动,如果没有服务,然后安装它,或者有更好的方法这样做


非常感谢您抽出时间

请尝试以下内容

- name: Check if service is up
  command: <command to check if service is up>
  register: output

- name: Install_SEP
  command: bash /usr/SEP/install.sh -i  
  when: "'running' not in output.stdout"
-name:检查服务是否已启动
命令:
寄存器:输出
-名称:安装
命令:bash/usr/SEP/install.sh-i
当:“'running'不在output.stdout中”
注意:我使用了running-in-when-condition:如果service命令返回特定的内容,则将其包括在内,而不是running

问:“我想检查服务是否启动,如果没有服务,然后安装它。”

这是可以使用的。例如,检查服务是否正在运行


(未测试)

检查服务是否正常的命令是什么?我还没有写。。我不知道该怎么说,非常感谢您的推荐,我使用了比您更高的灰烬溶液,效果很好:)但请您向我解释一下这是什么?dict2items json_query('[?value.state==
running
].key')“我得到了这个输出。它工作得很好,但后来停止了……我不明白为什么……致命:[172.17.64.17]:失败!=>{“changed”:true,“cmd:[“service”,“symcfgd”,“status”],“delta:“0:00:00.007976”,“end:“2019-10-10 13:49:26.042357”,“msg:“非零返回代码”,“rc”“:1,“开始”:“2019-10-10 13:49:26.034381”,“标准代码”:“symcfgd:未识别的服务”,“标准代码行”:[“symcfgd:未识别的服务”],“标准代码行”:“,”标准代码行“:[])可能是服务不存在,这就是它显示错误的原因。”。你可以给出ignore_errors:是的,对于第一个任务,我要检查的一件事是,如果没有服务,他会安装程序吗?将忽略错误:是会有帮助吗?
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') }}"