Ansible的hosts配置

仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述Ansible的hosts配置相关的知识,希望能为你提供帮助。
1、正常写法,name1为别名:
[test1]
name1 ansible_ssh_host=192.168.8.111 ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22
name2 ansible_ssh_host=192.168.8.222 ansible_ssh_user="root" ansible_ssh_pass="123456" 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 ping
?
【Ansible的hosts配置】ansible_ssh_host
将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
ansible_ssh_port
ssh端口号.如果不是默认的端口号,通过此变量设置.
ansible_ssh_user
默认的 ssh 用户名
ansible_ssh_pass
ssh 密码(这种方式并不安全,我们强烈建议使用 --ask-pass 或 SSH 密钥)
ansible_sudo_pass
sudo 密码(这种方式并不安全,我们强烈建议使用 --ask-sudo-pass)
ansible_sudo_exe (new in version 1.8)
sudo 命令路径(适用于1.8及以上版本)
ansible_connection
与主机的连接类型.比如:local, ssh 或者 paramiko. Ansible 1.2 以前默认使用 paramiko.1.2 以后默认使用 smart,smart 方式会根据是否支持 ControlPersist, 来判断ssh 方式是否可行.
ansible_ssh_private_key_file
ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况.
ansible_shell_type
目标系统的shell类型.默认情况下,命令的执行使用 sh 语法,可设置为 csh 或 fish

    推荐阅读