cans.systemd-unit-install
systemd-install-unit
安装和设置 systemd 单元。
此角色期望每个单元由以下格式的项描述:
- directory: "/some/other/path" # 安装单元的目录(默认: `systemd_unit_install_dir`)
remote: true # `unit` 路径是与本地机器还是远程主机相关(默认: False)
unit: "/path/to/unit.service" # 单元文件的路径(必须包括 `.service`, `.timer 等文件扩展名)。
user: true # 是否将服务作为用户服务安装/运行(而非系统范围的服务)。
state: "started" # 单元在下次启动时、立即启动还是不启动。
# 可选值: "disabled"(不启动)、"enabled"(下次启动时启动)或 "started"(立即启动)
tasks: # 字符串列表;用于实例化 systemd 模板(默认是 `[]`)
- "first"
- "second"
请注意,单元将通过 Ansible 的 template 安装。
要求
此角色仅适用于运行 systemd 的系统。也就是说,只有采用 systemd 的 Linux 发行版,例如:Debian(及其衍生版)、RedHat(及其衍生版)等。
角色变量
systemd_unit_install_dir
: 安装单元的目录;systemd_unit_install_units
: 要安装的单元列表,按照上述说明描述;systemd_unit_install_state
: 设置单元的默认状态(默认: 'enabled')systemd_unit_install_remote
: 单元文件是否来自本地或远程主机(默认: False)。systemd_unit_install_user
: 单元是作为系统服务安装(False)还是作为用户服务安装(True)(默认: False)。
依赖关系
此角色没有依赖关系。
示例剧本
- hosts: servers
roles:
# 从远程机器的文件安装一堆单元
- role: cans.systemd-install-unit
systemd_unit_install_remote: True
# 从本地文件安装一堆单元
- role: cans.systemd-install-unit
systemd_unit_install_units:
- unit: units/wonderful.service
directory: /usr/local/etc/systemd/system
- unit: units/critical.service
state: "started"
许可证
GPLv2
作者信息
版权 © 2017-2018, Nicolas CANIART。