qhdx07
作者qhdx07·2022-05-12 11:33
系统架构师·as

Ansible的hosts配置

字数 1529阅读 737评论 0赞 0

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_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'

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广