win_service存在时有条件吗



我正在创建在windows主机上安装fluentbit的剧本。一切都正常工作,但我在创建服务时遇到了错误,它并没有使安装失败,因为那时一切都已经就绪,但我想弄清楚如何利用条件。你能帮我吗?:(

我尝试从ansible.windows.win_service_info模块解析结果的即席测试如下:

---
- name: Check Windows service status
hosts: win
gather_facts: True
tasks:
- name: Check if a service is installed
win_service:
name: fluent-bit
register: service_info
- debug: msg="{{service_info}}"
- name: Get info for a single service
ansible.windows.win_service_info:
name: fluent-bit
register: service_info
- debug: msg="{{ service_info }}"
- name: Get info for a fluent-bit service
ansible.windows.win_service_info:
name: logging
register: service_exists
- debug: msg="{{ service_exists }}"
- name: Send message if service exists
debug:
msg: "Service is installed"
when: service_exists.state is not defined or service_exists.name is not defined
- name: Send message if service exists
debug:
msg: "Service is NOT installed"
when: service_exists.state is not running

我只是不知道如何解析输出,以便在流畅的位服务存在时跳过任务

TASK [debug] *****************************************************************************************
ok: [win-server-1] => {
"msg": {
"can_pause_and_continue": false,
"changed": false,
"depended_by": [],
"dependencies": [],
"description": "",
"desktop_interact": false,
"display_name": "fluent-bit",
**"exists": true,**
"failed": false,
"name": "fluent-bit",
"path": "C:\fluent-bit\bin\fluent-bit.exe -c C:\fluent-bit\conf\fluent-bit.conf",
"start_mode": "manual",
"state": "stopped",
"username": "LocalSystem"
}
}

干杯:(

所以,让它按照我想要的service_info.exists != True工作,现在如果服务已经存在,它将跳过任务。

相关内容

  • 没有找到相关文章

最新更新