Ansible with multiple SSH key pair

前端 未结 2 1309
天涯浪人
天涯浪人 2021-02-02 07:03

I am new to Ansible. I am able to test it and its working fine with my test requirment. For making connection between management node and the client node I am using already crea

2条回答
  •  死守一世寂寞
    2021-02-02 07:32

    tedder42 is correct, however, there is a better way of doing it.

    See ansible_ssh_private_key_file here.

    I have in my host files the following

    # SSH Keys configuration
    
    [all_servers:vars]
    ansible_ssh_private_key_file = 
    
    
    # Server configuration
    [all_servers:children]
    elastic_servers
    nginx_servers
    
    [elastic_servers]
    44.22.11.22
    44.55.66.77
    22.11.22.33
    
    [nginx_servers]
    22.24.123.123
    233.111.222.11
    

    If you have multiple keys configuration, you can do something like the following

    [nginx:vars]
    ansible_ssh_private_key_file = 
    [app:vars]
    ansible_ssh_private_key_file = 
    
    [nginx:children]
    nginx_servers
    
    [app:children]
    app_servers
    
    [nginx_servers]
    1.2.3.4
    [app_servers]
    5.5.5.5
    6.6.6.6
    

    That's way cleaner than tedder42 answer. This is useful if you have multiple keys for multiple servers.

    Otherwise, you can include your key in ansible.cfg file instead.

提交回复
热议问题