在Ansible中,你可以使用ansible_ssh_private_key_file
变量来指定SSH私钥文件。以下是一个示例解决方法:
ansible_ssh_private_key_file
变量。例如:[myhosts]
target_host ansible_ssh_host=192.168.1.100 ansible_ssh_private_key_file=/path/to/private_key.pem
ansible_ssh_private_key_file
变量。例如:- name: Example playbook
hosts: myhosts
vars:
ansible_ssh_private_key_file: /path/to/private_key.pem
tasks:
- name: Task 1
...
ansible_ssh_private_key_file
变量。例如:- name: Example playbook
hosts: myhosts
tasks:
- name: Task 1
shell: echo "Hello, world!"
environment:
ANSIBLE_SSH_PRIVATE_KEY_FILE: "{{ ansible_ssh_private_key_file }}"
在上述示例中,我们可以看到如何在不同的上下文中使用ansible_ssh_private_key_file
变量来指定SSH私钥文件。无论你选择哪种方法,都可以从变量中读取和使用该值。