ansible - Configuration of Host List

Keywords: Operation & Maintenance ansible Database

1. Configuration of ansible host list

The following are the source files after the installation of 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. Definition of ansible:

1) Indicate the host address or host name directly

test_2.xxxx.cn2         
192.168.200.132

2) Define a host group [group name] to add an address or host name

[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) If you don't use the public key and want to use the password, you can also write like this (for the first login control)

Format: [Host Name], [Designated User], [Host Address], [Host Password]
[webservers]
192.168.200.131    ansible_host_user=root    test-1=192.168.200.131      ansible_host_pass='123456'


Posted by brendan2b on Thu, 03 Oct 2019 05:22:08 -0700