【问题标题】:How can I tell which init system Ansible runs when I use the "service" module?当我使用“服务”模块时,如何判断 Ansible 运行的是哪个初始化系统?
【发布时间】:2017-01-16 14:05:06
【问题描述】:

来自the Ansible documentation,服务模块:

控制远程主机上的服务。支持的init系统包括BSD init、OpenRC、SysV、Solaris SMF、systemd、upstart。

对于给定的机器,我如何知道 Ansible 正在使用哪个初始化系统?例如,一个系统可能有 init 和 systemd。

【问题讨论】:

    标签: ansible init


    【解决方案1】:

    主机上的初始化系统可作为 Ansible fact ansible_service_mgr 使用。

    【讨论】:

    • 这在 ansible 版本之间是不一致的。我有 Ubuntu 可信赖的系统,其中 Ansible 2.2.1 报告“新贵”而 Ansible 2.4 报告“服务”。
    • 太棒了。现在下一个新手问题......如何根据这个事实做正确的ansible任务......
    • 你需要像这样在任务中添加when conditional:'when: ansible_service_mgr == "systemd"'
    • 修复了不正确的 ansible_service_mgr 问题:github.com/ansible/ansible/issues/30753
    【解决方案2】:

    让我们看看模块的code

    内部def main():

    # Find service management tools
    service.get_service_tools()
    

    然后到class LinuxService(Service):def get_service_tools(self):

        # Locate a tool to enable/disable a service
        if check_systemd():
            # service is managed by systemd
            ...
        elif location.get('initctl', False) and os.path.exists("/etc/init/%s.conf" % self.name):
            # service is managed by upstart
            ...
        elif location.get('rc-service', False):
            # service is managed by OpenRC
            ...
        elif self.svc_initscript:
            # service is managed by with SysV init scripts
            ...
    

    我已经剪掉了一些代码,但是这个 sn-p 应该回答你的问题:如果有很多系统 Ansible 可能会选择什么。

    Systemd 是第一个搜索的,然后是暴发户,等等......

    【讨论】:

    • 我认为这不是一个好主意。在我的 Ubuntu 14 服务器上,我安装了 systemd,但没有用于 init。结果是 Ansible 尝试使用 Systemd 而不是 Upstart(系统声明的服务管理器)
    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2013-09-14
    相关资源
    最近更新 更多