博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ansible之service和server模块
阅读量:5793 次
发布时间:2019-06-18

本文共 2665 字,大约阅读时间需要 8 分钟。

service模块介绍

例:启动指定节点上的httpd 服务,并让其开机自启动

[root@master tmp]# ansible client02 -m service -a 'name=httpd state=restarted enabled=yes'client02 | SUCCESS => {    "changed": true,     "enabled": true,     "name": "httpd",     "state": "started"}[root@client01 tmp]# ps -ef|grep httpd|wc -l                                1[root@client02 tmp]# ps -ef|grep httpd|wc -l9

server模块介绍

可以提供的status:running,started,stopped,restarted,reloaded[root@master tmp]# cat /etc/ansible/hosts[localhost]master.test.com[slave]client02client01此处参数  -s 意思是run operations with sudo (nopasswd) (deprecated, use                        become)结尾参数-k 意思是要让输入ssh 密码例:检查某节点的httpd 服务[root@master ~]# ansible slave -m service -a "name=httpd state=running" –s[root@master tmp]# ansible client02 -m service -a "name=httpd state=running" -sclient02 | SUCCESS => {    "changed": false,     "name": "httpd",     "state": "started"}[root@master tmp]# ansible slave -m service -a "name=httpd state=stopped" -kSSH password: 111111client01 | SUCCESS => {    "changed": false,     "name": "httpd",     "state": "stopped"}client02 | SUCCESS => {    "changed": false,     "name": "httpd",     "state": "stopped"}[root@master tmp]# ansible client02 -m service -a "name=httpd state=status" -sclient02 | FAILED! => {    "changed": false,     "failed": true,     "msg": "value of state must be one of: running,started,stopped,restarted,reloaded, got: status"}[root@master tmp]# ansible client02 -m service -a "name=httpd state=stopped" -sclient02 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "stopped"}[root@master tmp]# ansible client01 -m service -a "name=httpd state=running" -sparamiko: The authenticity of host 'client01' can't be established.The ssh-rsa key fingerprint is 3d906ef1d450e4cc7031aef5e8c296f6.Are you sure you want to continue connecting (yes/no)?yesclient01 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "started"}[root@master tmp]# ansible slave -m service -a "name=httpd state=started" -sclient02 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "started"}client01 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "started"}[root@client01 tmp]# ps -ef|grep httpd|wc -l10[root@client02 tmp]# ps -ef|grep httpd|wc -l10[root@master tmp]# ansible slave -m service -a "name=httpd state=stopped" -sclient02 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "stopped"}client01 | SUCCESS => {    "changed": true,     "name": "httpd",     "state": "stopped"}

[root@client01 tmp]# ps -ef|grep httpd|wc -l

1
[root@client02 tmp]# ps -ef|grep httpd|wc -l
1

转载于:https://blog.51cto.com/wujianwei/2082900

你可能感兴趣的文章
华为硬件工程师笔试题
查看>>
jquery居中窗口-页面加载直接居中
查看>>
cd及目录快速切换
查看>>
Unity Shaders and Effects Cookbook (3-5) 金属软高光
查看>>
31-hadoop-hbase-mapreduce操作hbase
查看>>
C++ 代码风格准则:POD
查看>>
linux-友好显示文件大小
查看>>
【转】【WPF】WPF中MeasureOverride ArrangeOverride 的理解
查看>>
【转】二叉树的非递归遍历
查看>>
NYOJ283对称排序
查看>>
接连遇到大牛
查看>>
[Cocos2d-x For WP8]矩形碰撞检测
查看>>
自己写spring boot starter
查看>>
花钱删不完负面消息
查看>>
JBPM之JPdl小叙
查看>>
Membership三步曲之进阶篇 - 深入剖析Provider Model
查看>>
前端优化及相关要点总结
查看>>
struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
查看>>
25 个精美的手机网站模板
查看>>
C#反射实例应用--------获取程序集信息和通过类名创建类实例
查看>>