how to define ssh private key for servers fetched by dynamic inventory in files

前端 未结 5 1174
小蘑菇
小蘑菇 2020-12-12 15:32

I met one configuration problem when coding ansible playbook for ssh private key file.

As we know, we can define combination with host server, ip & related ssh p

5条回答
  •  猫巷女王i
    2020-12-12 16:09

    I had a similar issue and solved it with a patch to ec2.py and adding some configuration parameters to ec2.ini. The patch takes the value of ec2_key_name, prefixes it with the ssh_key_path, and adds the ssh_key_suffix to the end, and writes out ansible_ssh_private_key_file as this value.

    The following variables have to be added to ec2.ini in a new 'ssh' section (this is optional if the defaults match your environment):

    [ssh]
    # Set the path and suffix for the ssh keys
    ssh_key_path = ~/.ssh
    ssh_key_suffix = .pem
    

    Here is the patch for ec2.py:

    204a205,206
    >     'ssh_key_path': '~/.ssh',
    >     'ssh_key_suffix': '.pem',
    422a425,428
    >         # SSH key setup
    >         self.ssh_key_path = os.path.expanduser(config.get('ssh', 'ssh_key_path'))
    >         self.ssh_key_suffix = config.get('ssh', 'ssh_key_suffix')
    > 
    1490a1497
    >         instance_vars["ansible_ssh_private_key_file"] = os.path.join(self.ssh_key_path, instance_vars["ec2_key_name"] + self.ssh_key_suffix)
    

提交回复
热议问题