温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

inventory主机清单和变量介绍

发布时间:2020-06-01 11:46:21 来源:亿速云 阅读:548 作者:Leah 栏目:云计算

这篇文章的知识点包括inventory的主机清单和inventory的变量介绍,知识点都是大家经常用到的,为此分享给大家做个参考。一起跟随小编过来看看吧。

inventory主机清单

ansible默认的主机清单是/etc/ansible/hosts文件
主机清单可以手动设置,也可以通过Dynamic Inventory动态生成
一般主机名使用FQDN

vi /etc/ansible/hosts
[webserver]      #方括号设置组名
www1.example.org    #定义被监控主机,这边可以是主机名也可以是IP地址,主机名需要修改/etc/hosts文件
www2.example.org:2222     #冒号后定义远程连接端口,默认是ssh的22端口

如果是名称类似的主机,可以使用列表的方式标识各个主机
[webserver]
www[01:50].example.org ansible_ssh_user=root ansible_ssh_pass=123456

[dbbservers]
db-[a:f].example.org

下面是Inventory中变量

(1)主机变量

[webserver]

www1.magedu.com http_port=80 maxRequestsChild=808 www2.magedu.com http_port=8080 maxRequestsChild=909 (2)组变量 [servers:vars] ntp_server=ntp.example.org nfs_server=nfs.example.org (3)组嵌套 [apache] http1.example.org http2.example.org [nginx] ngx1.example.org ngx2.example.org [webservers:children] apache nginx (4)inventory变量参数 参数                          说明 ansible_ssh_host    将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置. ansible_ssh_port    ssh端口号.如果不是默认的端口号,通过此变量设置. ansible_ssh_user    默认的 ssh 用户名 ansible_ssh_pass    ssh 密码(这种方式并不安全,我们强烈建议使用 --ask-pass 或 SSH 密钥) ansible_ssh_private_key_file    ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况. ansible_ssh_common_args 此设置附加到sftp,scp和ssh的缺省命令行 ansible_sftp_extra_args 此设置附加到默认sftp命令行。 ansible_scp_extra_args  此设置附加到默认scp命令行。 ansible_ssh_extra_args  此设置附加到默认ssh命令行。 ansible_ssh_pipelining  确定是否使用SSH管道。 这可以覆盖ansible.cfg中得设置。 ansible_shell_type  目标系统的shell类型.默认情况下,命令的执行使用 'sh' 语法,可设置为 'csh' 或 'fish'. ansible_python_interpreter  目标主机的 python 路径.适用于的情况: 系统中有多个 Python, 或者命令路径不是"/usr/bin/python",比如 *BSD, 或者 /usr/bin/python ansible_*_interpreter   这里的"*"可以是ruby 或perl 或其他语言的解释器,作用和ansible_python_interpreter 类似 ansible_shell_executable    这将设置ansible控制器将在目标机器上使用的shell,覆盖ansible.cfg中的配置,默认为/bin/sh。

看完上述内容,你们对inventory主机清单和变量有进一步的了解吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI