我有
systemd
服务列表
vars:
systemd_scripts: ['a.service', 'b.service', 'c.service']
现在我只想停止上面列表中的
a.service
。这如何使用systemd
_module来实现?
你想达到什么目的?正如所写,你可以这样做:
- name: Stop service A
systemd:
name: a.service
state: stopped
如果您的意思是“第一服务”,请使用
first
过滤器或索引:
- name: Stop first service
systemd:
name: "{{ systemd_scripts | first }}"
state: stopped
或
- name: Stop first service
systemd:
name: "{{ systemd_scripts[0] }}"
state: stopped
你的问题非常模糊和不具体。但是,您的部分问题可以用以下方法回答
- name: Loop over service list and stop one service
systemd:
name: "{{ item }}"
state: stopped
when:
- systemd_scripts[item] == 'a.service'
with_items: "{{ systemd_scripts }}"
您可能需要根据您的需要和所需功能扩展和更改它。
service_facts
) 和systemd
你可以看看
进一步阅读