ansible学习(2):清单配置详情

2019-10-30  本文已影响0人  August________

ansible学习(2):清单配置详情

配置文件写上受管理的主机

]# tail -n 5 /etc/ansible/hosts 
## db-[99:101]-node.example.com

test1 ansible_host=192.168.13.132 ansible_port=22 ansible_user=root ansible_ssh_pass=123456
test2 ansible_host=192.168.13.134 ansible_port=22 ansible_user=root ansible_ssh_pass=123456
test3 ansible_host=192.168.13.133 ansible_port=22 ansible_user=root ansible_ssh_pass=123456

[root@ansible ~]# ansible test1 -m ping
test1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
[root@ansible ~]# ansible test2 -m ping
test2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

使用“all”关键字,一次性去操作清单下的所有主机。

[root@ansible ~]# ansible all -m ping
test1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
test2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
test3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

"分组功能"

[root@ansible ~]# tail -n 5 /etc/ansible/hosts
test1 ansible_host=192.168.13.132 ansible_port=22 ansible_user=root ansible_ssh_pass=123456
test2 ansible_host=192.168.13.134 ansible_port=22 ansible_user=root ansible_ssh_pass=123456

[B]
test3 ansible_host=192.168.13.133 ansible_port=22 ansible_user=root ansible_ssh_pass=123456

[root@ansible ~]# ansible A -m ping
test2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
test1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}


[root@ansible ~]# ansible B -m ping
test3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
 

[root@ansible Software]# tail -n 15 /etc/ansible/hosts 

#[B]
#test3 ansible_host=192.168.13.133 ansible_port=22 ansible_user=root ansible_ssh_pass=123456
all:
 hosts:
#  192.168.13.130:
  test1:
   ansible_host: 192.168.13.132
   ansible_port: 22
  test2:
   ansible_host: 192.168.13.134
   ansible_port: 22
  test3:
   ansible_host: 192.168.13.133
   ansible_port: 22
[root@ansible Software]# 

# ansible all -m ping
test3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
test1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
test2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

上一篇 下一篇

猜你喜欢

热点阅读