1. yaml
2. 写清单
- 缩进使用两个空格
[root@server4 ansible]# vim hosts
all:
hosts:
172.25.60.5:
172.25.60.6:
[root@server4 ansible]# ansible all -m ping
172.25.60.5 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
172.25.60.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
- 定义组
[root@server4 ansible]# vim hosts
all:
hosts:
172.25.60.6:
children:
test1:
hosts:
172.25.60.3:
test2:
hosts:
172.25.60.5:
[root@server4 ansible]# ansible all -m ping
172.25.60.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
172.25.60.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
172.25.60.5 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[root@server4 ansible]# ansible test1 -m ping
172.25.60.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[root@server4 ansible]# ansible test2 -m ping
172.25.60.5 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
- 定义子组
[root@server4 ansible]# vim hosts
all:
children:
pro:
children:
proA:
hosts:
172.25.60.6:
proB:
hosts:
172.25.60.5:
[root@server4 ansible]# ansible pro -m ping
172.25.60.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
172.25.60.5 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[root@server4 ansible]# ansible proA -m ping
172.25.60.6 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[root@server4 ansible]# ansible proB -m ping
172.25.60.5 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
- 使用别名的方式配置受管主机
[root@server4 ansible]# vim hosts
all:
hosts:
172.25.60.6:
server3:
ansible_host: 172.25.60.3 # 在:之后有一个空格
172.25.60.5:
[root@server4 ansible]# ansible server3 -m ping
server3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}