Ansible hosts文件写法(学习笔记八)

简介: 1、正常写法,name1为别名:[test1]name1 ansible_ssh_host=192.168.1.111 ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22name2 ansible_ssh_host=192.

1、正常写法,name1为别名:
[test1]
name1 ansible_ssh_host=192.168.1.111 ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22
name2 ansible_ssh_host=192.168.1.222 ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22

2、连续的IP写法,表示192.168.1.20到192.168.1.50,共31台主机:
[test1]
name1 ansible_ssh_host=192.168.1.[20:50] ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22

3、带参数的群组,vars底下为群组共同便变量,包括已定义变量和自定义变量:
[test1]
name1 ansible_ssh_host=192.168.1.[20:50]
[test1:vars]
ansible_ssh_user=root
ansible_ssh_pass="1234"
testvar="test"

4、群组整合,children底下为父群组test的子群组,调用方式为ansible test -m ping:
[dbtest]
name1 ansible_ssh_host=192.168.1.[20:50] ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22
[webtest]
name2 ansible_ssh_host=192.168.2.[20:50] ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22
[test:children]
dbtest
webtest

5、调用两个主机组的写法,以下webservers和dbservers都会被调用:
ansible webservers:dbservers -m win_ping

6、在webservers组中但不在dbsersers中的调用:
ansible webservers:!dbservers -m win_ping

7、在webservers组中并且在dbservers组中的才会调用:
ansible webservers:&dbservers -m win_ping

8、在调用前加~,代表正则表达式:
ansible ~(web|db).*.91it.org -m win_ping

9、组合的例子:
webserver:dbservers:&nginx:!ntp

10、hosts文件中没有定义的IP或别名,在进行调用中,会提示错误。ansible对单台服务器的调用,服务器IP或域名必须有写在hosts里。

目录
相关文章
「译文」如何在 Ansible 中复制多个文件和目录
「译文」如何在 Ansible 中复制多个文件和目录
|
9月前
|
应用服务中间件 PHP nginx
ansible:roles学习笔记
ansible:roles学习笔记
71 0
|
9月前
|
应用服务中间件 Linux 数据安全/隐私保护
ansible:playbook学习笔记
ansible:playbook学习笔记
98 0
|
运维 安全 测试技术
运维工程师日常工作解析及 Ansible 全面介绍| 学习笔记
快速学习运维工程师日常工作解析及 Ansible 全面介绍
246 0
运维工程师日常工作解析及 Ansible 全面介绍| 学习笔记
|
XML NoSQL 关系型数据库
实现 Ansible 企业级用法 playbook| 学习笔记
快速学习实现 Ansible 企业级用法 playbook
185 0
实现 Ansible 企业级用法 playbook| 学习笔记
|
JSON 运维 Shell
Ansible 使用和模块化深入解析| 学习笔记
快速学习 Ansible 使用和模块化深入解析
116 0
|
缓存 运维 关系型数据库
Ansible 实现 role 运维自动化高级用法| 学习笔记
快速学习 Ansible 实现 role 运维自动化高级用法
287 0
Ansible 实现 role 运维自动化高级用法| 学习笔记
|
JSON 运维 Linux
Ansible 工作架构和原理| 学习笔记
快速学习 Ansible 工作架构和原理
376 0
Ansible 工作架构和原理| 学习笔记
|
缓存 运维 应用服务中间件
Ansible 常见企业级应用模块实战| 学习笔记
快速学习 Ansible 常见企业级应用模块实战
97 0
|
运维 Linux 网络安全
Ansible 训练营|学习笔记
快速学习 Ansible 训练营
100 0
Ansible  训练营|学习笔记