ansible之service和server模块
可以提供的status:running,started,stopped,restarted,reloaded # cat /etc/ansible/hostsmaster.test.com
client02
client01
此处参数-s 意思是
run operations with sudo (nopasswd) (deprecated, use
become)
结尾参数-k 意思是要让输入ssh 密码
例:检查某节点的httpd 服务
# ansible slave -m service -a "name=httpd state=running" –s
# ansible client02 -m service -a "name=httpd state=running" -s
client02 | SUCCESS => {
"changed": false,
"name": "httpd",
"state": "started"
}
# ansible slave -m service -a "name=httpd state=stopped" -k
SSH password: 111111
client01 | SUCCESS => {
"changed": false,
"name": "httpd",
"state": "stopped"
}
client02 | SUCCESS => {
"changed": false,
"name": "httpd",
"state": "stopped"
}
# ansible client02 -m service -a "name=httpd state=status" -s
client02 | FAILED! => {
"changed": false,
"failed": true,
"msg": "value of state must be one of: running,started,stopped,restarted,reloaded, got: status"
}
# ansible client02 -m service -a "name=httpd state=stopped" -s
client02 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "stopped"
}
# ansible client01 -m service -a "name=httpd state=running" -s
paramiko: 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)?
yes
client01 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "started"
}
# ansible slave -m service -a "name=httpd state=started" -s
client02 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "started"
}
client01 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "started"
}
# ps -ef|grep httpd|wc -l
10
# ps -ef|grep httpd|wc -l
10
# ansible slave -m service -a "name=httpd state=stopped" -s
client02 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "stopped"
}
client01 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "stopped"
}
页:
[1]