[英]Start only specific systemd service from list of services using Ansible
What are you trying to achieve?你想达到什么目的? As written, you could just do:
如所写,您可以这样做:
- name: Stop service A
systemd:
name: a.service
state: stopped
If instead you mean "the first service", use the first
filter or an index:如果您的意思是“第一个服务”,请使用第
first
过滤器或索引:
- name: Stop first service
systemd:
name: "{{ systemd_scripts | first }}"
state: stopped
OR或者
- name: Stop first service
systemd:
name: "{{ systemd_scripts[0] }}"
state: stopped
Your question is very vague and unspecific.你的问题非常模糊和不具体。 However, parts of your question could be answered with the following approach
但是,您的部分问题可以通过以下方法回答
- name: Loop over service list and stop one service
systemd:
name: "{{ item }}"
state: stopped
when:
- systemd_scripts[item] == 'a.service'
with_items: "{{ systemd_scripts }}"
You may need to extend and change it for your needs and required functionality.您可能需要根据需要和所需功能对其进行扩展和更改。
Regarding discovering, starting and stopping services via Ansible facts ( service_facts
) and systemd
you may have a look into关于通过 Ansible 事实(
service_facts
)和systemd
发现、启动和停止服务,您可以查看
Further readings进一步阅读
service_facts
?service_facts
声明一个变量?service_facts
module in an Ansible playbook?service_facts
模块检查服务是否存在和未安装在服务器中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.