当前位置 : 主页 > 操作系统 > centos >

Ansible Service模块手册

来源:互联网 收集:自由互联 发布时间:2022-06-20
Service模块 启动nginx服务: ansible all -m service -a "name=nginx state=started" 关闭nginx服务: ansible all -m service -a "name=nginx state=stopped" 设置nginx开机自启动: ansible all -m service -a "name='nginx' enabled=yes" 重

Service模块

启动nginx服务:

ansible all -m service -a "name=nginx state=started"

Ansible Service模块手册_Ansible Service模块手册

关闭nginx服务:

ansible all -m service -a "name=nginx state=stopped"

Ansible Service模块手册_ansible_02

设置nginx开机自启动:

ansible all -m service -a "name='nginx' enabled=yes"

Ansible Service模块手册_Ansible Service模块手册_03

 

重启nginx服务,设置开机自启动:

ansible all -m service -a 'name=nginx state=restarted enabled=yes'

Ansible Service模块手册_Ansible Service模块手册_04

Playbook service模块写法:

启动nginx服务,并设置开机自启动。

[root@master ~]# cat svc.yml
- hosts: all
tasks:
- name: Enable service httpd, and not touch the state
service:
name: nginx
state: started
enabled: yes

 Ansible Service模块手册_Ansible Service模块手册_05

下面这个参数不会使用,本来想尝试reids和mongo的,结果发现不行,哪位大佬知道咋用》评论区回复。

- name: Start service foo, based on running process /usr/bin/foo

  service:

    name: foo

    pattern: /usr/bin/foo

    state: started

 

Service模块中 notify、 handlers触发器的使用:

[root@master ~]# cat svc2.yml
---
- hosts: all
remote_user: root
vars:
- pkg: nginx
tasks:
- name: "install nginx package."
yum: name={{ pkg }} state=installed
- name: "copy httpd configure file to remote host."
copy: content="hello mew" dest=/usr/share/nginx/index.html
notify: restart nginx # 当这个任务执行状态发生改变时,触发handlers执行.
- name: "boot httpd service."
service: name=nginx state=started
handlers: # handlers与tasks是同一级别
- name: restart nginx
service: name=nginx state=restarted

 Ansible Service模块手册_Ansible Service模块手册_06

 

上一篇:性能工具之Jmeter压测WebSocket接口
下一篇:没有了
网友评论