我正在尝试从 scan_services 模块(或 >= 2.5 中的 service_facts )的输出中过滤掉正在运行的服务。这个模块的输出是这样的:
"ansible_facts": {
"services": {
"NetworkManager-dispatcher.service": {
"name": "NetworkManager-dispatcher.service",
"source": "systemd",
"state": "running"
},
"NetworkManager-wait-online.service": {
"name": "NetworkManager-wait-online.service",
"source": "systemd",
"state": "stopped"
},
"NetworkManager.service": {
"name": "NetworkManager.service",
"source": "systemd",
"state": "running"
},
现在,我要做的是仅列出处于状态的服务名称:正在运行...此代码似乎根本不起作用:/
---
- hosts: all
tasks:
- name : Scan current services status
scan_services:
register: running_services
- name: print
debug: var=item
with_items: "{{ running_services.|json_query('ansible_facts.services.[?state=='running'].name')}}"
...但我想我在附近的某个地方。我想这个 json_query 中缺少一些东西:(