ansible服务模块在服务实际运行时将服务状态返回为stopped

x33g5p2x  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(255)

尝试使用ansible 2.7停止服务(dse datastax enterprise)

- name: Stop service dse, if started
 service:
  name: dse
  state: stopped

我想ansible说的是,我什么都没做,因为这个服务已经停止了。详细输出的一部分:

ok: [myhostname.domain.com] => {
"changed": false,
"invocation": {
    "module_args": {
        "daemon_reload": false,
        "enabled": null,
        "force": null,
        "masked": null,
        "name": "dse",
        "no_block": false,
        "scope": null,
        "state": "stopped",
        "user": null
    }
},
"name": "dse",
"state": "stopped",

当我检查远程主机上的服务时,这就是我看到的

[user@remotehost ~]$ service dse status
dse is running

那我还缺什么?仅供参考,建议您 sudo service dse stop 对于这项服务,我不知道是否缺乏 sudo 会有很大的不同。

ee7vknir

ee7vknir1#

我对这一点的理解是因为我没有一个无限制的sudo,并且我没有在/bin/sh中执行的能力,因此它是失败的。
当直接在服务器上运行时,同样的命令也会起作用,这是因为
ansible发送python代码在目标服务器上执行。由于ansible运行的是python代码,通常不直接执行系统命令,因此不能用sudo限制系统命令,而期望它们与ansible一起工作。更多:https://gist.github.com/nanobeep/3b3d614a709086ff832a
不确定每个人都有这样的奢侈,但在我的情况下修改sudoers文件
TheGroupNameImPartOf ALL= ALL, !SU, !SHELLSTheGroupNameImPartOf ALL= ALL 你变魔术了!

相关问题