ansible 主机清单 /etc/ansible/hosts




主机清单 [webservers] ansible01 ansible02 ansible03 ansible04

  

 

[root@ftp:/root]
> ansible webservers -u root -k -m ping -o 
SSH password: 
ansible03 | SUCCESS => {"changed": false, "ping": "pong"}
ansible01 | SUCCESS => {"changed": false, "ping": "pong"}
ansible02 | SUCCESS => {"changed": false, "ping": "pong"}
ansible04 | SUCCESS => {"changed": false, "ping": "pong"}

[root@ftp:/root]
>

 

Ansible Inventory 内置参数

 

 

 

 

 

 

[root@ftp:/root]
> ansible webservers -m ping -o 
ansible01 | SUCCESS => {"changed": false, "ping": "pong"}
ansible04 | SUCCESS => {"changed": false, "ping": "pong"}
ansible03 | SUCCESS => {"changed": false, "ping": "pong"}
ansible02 | SUCCESS => {"changed": false, "ping": "pong"}






[webservers]

ansible01 ansible_ssh_port='22'

ansible[02:04] 

[webservers:vars]
ansible_ssh_user='root' 
ansible_ssh_pass='AAbb0101'

  

分组

 

[webservers]

ansible[01:04] 

[apache]
ansible[01:02]

[nginx]
ansible[03:04]

[webservers:children]
apache
nginx

[webservers:vars]
ansible_ssh_user='root'
ansible_ssh_pass='AAbb0101'

 

 

 

[root@ftp:/root]
> ansible apache -m ping -o 
ansible01 | SUCCESS => {"changed": false, "ping": "pong"}
ansible02 | SUCCESS => {"changed": false, "ping": "pong"}

[root@ftp:/root]
> ansible nginx -m ping -o 
ansible03 | SUCCESS => {"changed": false, "ping": "pong"}
ansible04 | SUCCESS => {"changed": false, "ping": "pong"}

 

 

列出主机清单

[root@ftp:/root]
> ansible nginx --list-hosts
  hosts (2):
    ansible03
    ansible04

[root@ftp:/root]
> ansible apache --list-hosts
  hosts (2):
    ansible01
    ansible02


[root@ftp:/root]
> ansible webservers --list-hosts
  hosts (4):
    ansible01
    ansible02
    ansible03
    ansible04

[root@ftp:/root]
> 

 

 

 

 

自定义指定新的主机清单文件:

[root@ftp:/]
> ansible -i /home/docker dockers -m ping -o 
ansible01 | SUCCESS => {"changed": false, "ping": "pong"}
ansible02 | SUCCESS => {"changed": false, "ping": "pong"}

[root@ftp:/]
> cat /home/docker
[dockers]
ansible01
ansible02
[dockers:vars]
ansible_ssh_user='root'
ansible_ssh_pass='AAbb0101'

 

转载于:https://www.cnblogs.com/liweiming/p/10547539.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值