ansible:yaml写清单

目录标题


1. yaml

在这里插入图片描述

2. 写清单

  1. 缩进使用两个空格
[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"
}
  1. 定义组
[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"
}
  1. 定义子组
[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"
}
  1. 使用别名的方式配置受管主机
[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"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值