patterns

Patterns:

主题

在Ansible中,Patterns 是指我们怎样确定由哪一台主机来关机,意思就是与哪台主机进行交互,

ansible webservers -m service -a "name=httpd state=restarted

一个pattern 通常关联到一系列组(主机的集合)--如上示例中,所有的主机均在“webservers” 组中.


不管怎么样,在使用Ansible前,我们需要事先告诉Ansible哪台机器将被执行,能这样做的前提是需要预先

定义唯一的host names或者主机组


[root@node01 ~]# ansible webservers -m service -a "name=httpd state=restarted"
192.168.137.3 | SUCCESS => {
    "changed": true, 
    "failed": false, 
    "name": "httpd", 
    "state": "started"
}

[root@node01 ~]# ansible webservers -m service -a "name=httpd state=stopped"
192.168.137.3 | SUCCESS => {
    "changed": true, 
    "failed": false, 
    "name": "httpd", 
    "state": "stopped"
}

[root@node01 ~]# ansible webservers -m service -a "name=httpd state=started"
192.168.137.3 | SUCCESS => {
    "changed": true, 
    "failed": false, 
    "name": "httpd", 
    "state": "started"
}

原文地址:https://www.cnblogs.com/hzcya1995/p/13349384.html