温馨提示×

温馨提示×

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

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

ansible-主机清单的配置

发布时间:2020-07-22 00:58:53 来源:网络 阅读:287 作者:跳跳弹 栏目:系统运维

1. ansible主机清单的配置

    以下是ansible安装完成后的源文件

[root@test-1 ~]# cat /etc/ansible/hosts
    # This is the default ansible 'hosts' file.
    #
    # It should live in /etc/ansible/hosts
    #
    #   - Comments begin with the '#' character
    #   - Blank lines are ignored
    #   - Groups of hosts are delimited by [header] elements
    #   - You can enter hostnames or ip addresses
    #   - A hostname/ip can be a member of multiple groups
    
    # Ex 1: Ungrouped hosts, specify before any group headers.
    [webservers]
    192.168.200.131  ansible_host_user=root ansible_host_pass='123456'
    192.168.200.132
    192.168.200.133
    192.168.200.134
    192.168.200.135
    192.168.200.136
    
    ## green.example.com
    ## blue.example.com
    ## 192.168.100.1
    ## 192.168.100.10
    
    # Ex 2: A collection of hosts belonging to the 'webservers' group
    
    ## [webservers]
    ## alpha.example.org
    ## beta.example.org
    ## 192.168.1.100
    ## 192.168.1.110
    
    # If you have multiple hosts following a pattern you can specify
    # them like this:
    
    ## www[001:006].example.com
    
    # Ex 3: A collection of database servers in the 'dbservers' group
    
    ## [dbservers]
    ## 
    ## db01.intranet.mydomain.net
    ## db02.intranet.mydomain.net
    ## 10.25.1.56
    ## 10.25.1.57
    
    # Here's another example of host ranges, this time there are no
    # leading 0s:
    
    ## db-[99:101]-node.example.com

2. ansible定义方式:

 1) 直接指明主机地址或主机名

test_2.xxxx.cn2         
192.168.200.132

   2) 定义一个主机组 [  组名  ]  把地址或主机名加进去

[webservers]
        192.168.200.131  ansible_host_user=root ansible_host_pass='123456'
        192.168.200.132
        192.168.200.133
        192.168.200.134
        192.168.200.135
        192.168.200.136

 3) 如果你没有使用公钥,想要使用密码,你也可以这样写(适用于第一次登陆控制)

格式:【主机名】       【指定用户】    【主机地址】   【主机密码】
[webservers]
192.168.200.131    ansible_host_user=root    test-1=192.168.200.131      ansible_host_pass='123456'


向AI问一下细节

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

AI