gpt4 book ai didi

Ansible - 编辑 systemd 服务文件

转载 作者:行者123 更新时间:2023-12-05 00:44:55 25 4
gpt4 key购买 nike

systemd 模块:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/systemd_module.html

我正在寻找一种将条件添加到服务文件的方法。

例如:

ConditionPathIsMountPoint=/mnt/myreplication/path/

这对于 docker 安装很有用,确保 docker 在需要的挂载实际可用之前不会启动容器。

遗憾的是,Ansible 目前似乎不支持添加此功能。我在那里正确吗?我需要手动添加它,还是使用 lineinfile?还是有别的办法?

编辑:这个问题似乎正在获得意见,所以我会添加这个:

https://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services

这是我另一个问题的答案:https://askubuntu.com/a/1348117/1612

引用它:

Don't edit files in /lib/systemd/ or /usr/share/systemd as they will get overwritten on updates.

最佳答案

让我使用适合我的 ini_file 发布解决方案:

- name: Create a foo.service override directory
file:
owner: root
group: root
mode: 0755
path: /etc/systemd/system/foo.service.d
state: directory
- name: Set up foo.service override
ini_file:
dest: /etc/systemd/system/foo.service.d/bar_override.conf
owner: root
group: root
mode: 0644
section: Unit
option: ConditionPathIsMountPoint
value: /mnt/myreplication/path/

这避免了重写原始服务文件,而是将专用覆盖添加到 .d 子目录中。

请注意,ini_file= 周围添加空格,如

[Unit]
ConditionPathIsMountPoint = /mnt/myreplication/path/

但这很好,见 systemd.syntax(7) :

Each file is a plain text file divided into sections, with configuration entries in the style key=value. Whitespace immediately before or after the "=" is ignored.

关于Ansible - 编辑 systemd 服务文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65092169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com