How to check service exists and is not installed in the server using service_facts module in an Ansible playbook?(如何使用Ansible攻略中的SERVICE_FACTS模块检查服务器中是否存在服务?)
本文介绍了如何使用Ansible攻略中的SERVICE_FACTS模块检查服务器中是否存在服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用service_facts检查服务是否正在运行并已启用。在某些服务器中,未安装特定软件包。
现在,我如何使用service_facts module知道此特定软件包未安装在该特定服务器上?
在Ansible攻略中,它显示以下错误:
localhost | SUCCESS => {
"ansible_facts": {
"services": {
"acpid.service": {
"name": "acpid.service",
"source": "systemd",
"state": "running",
"status": "enabled"
},
"agent_installation.service": {
"name": "agent_installation.service",
"source": "systemd",
"state": "stopped",
"status": "unknown"
}, "changed": false,
"msg": "WARNING: Could not find status for all services. Sometimes this is due to insufficient privileges."
}
推荐答案
特定服务只有在存在且已正确注册的情况下才能在service_facts下可用。如果您想在不知道是否存在的服务上执行任务,Conditionals可能适合您。在示例中
- name: Gathering Service Facts
service_facts:
tags: remove,stop,disable
- name: Make sure {{ SERVICE }} is stopped and disabled
systemd:
name: {{ SERVICE }}
state: stopped
enabled: no
when: ("{{ SERVICE }}" in services)
tags: remove,stop,disable
- name: Make sure {{ SERVICE }} is removed
yum:
name: {{ SERVICE }}
state: absent
tags: remove
您可以这样做
- name: Set facts
set_fact:
SERVICE: "postgresql-10.service" for my working test environment
tags: facts
- name: Gathering service facts
service_facts:
tags: facts
- name: Get facts
debug:
msg:
- "{{ ansible_facts.services[SERVICE].status }}"
tags: facts
这篇关于如何使用Ansible攻略中的SERVICE_FACTS模块检查服务器中是否存在服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:如何使用Ansible攻略中的SERVICE_FACTS模块检查服务器中是否存在服务?
基础教程推荐
猜你喜欢
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
