简体   繁体   English

如何使用Ansible安装systemd服务?

[英]How can I install a systemd service using Ansible?

I want to install a systemd service from a Jinja2 template. 我想从Jinja2模板安装systemd服务。 How do I do this? 我该怎么做呢?

Do I have to use copy module to copy the file to /lib/systemd/system and then use systemd module to enable it? 我是否必须使用copy模块将文件复制到/lib/systemd/system然后使用systemd模块启用它?

Is there a better way? 有没有更好的办法?

I use the template module to install the .service file into the /etc/systemd/system . 我使用template模块将.service文件安装到/etc/systemd/system According to this digital ocean blog post /lib/systemd/system should be reserved for packages bundled with the OS itself, and third party services should be defined in /etc/systemd/system . 根据这个数字海洋博客文章 /lib/systemd/system应保留与操作系统本身捆绑的软件包,第三方服务应在/etc/systemd/system定义。

With ansible's systemd module I'd start the service with daemon_reload=yes . 使用ansible的systemd模块,我将使用daemon_reload=yes启动服务。

Prior to Ansible 2.2 : I do a systemctl daemon-reload afterward (can use an ansible handler for this if appropriate) to prod systemd to pick up the new file. 在Ansible 2.2之前 :我之后做了一个systemctl daemon-reload (如果合适,可以使用一个ansible处理程序)来prod systemd来获取新文件。

- name: install myservice systemd unit file
  template: src=myservice.j2 dest=/etc/systemd/system/myservice.service

- name: start myservice
  systemd: state=started name=myservice daemon_reload=yes


# For ansilble < 2.2 only
#- name: reload systemd unit configuration
#  command: systemctl daemon-reload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM