问题描述:
在使用Ansible时,用户无法通过网络共享进行身份验证。
解决方法:
$ ssh-keygen
$ ssh-copy-id @
host_key_checking
设置为False,以允许自动接受新主机的密钥:[defaults]
host_key_checking = False
- name: Configure SSH agent forwarding
hosts: all
tasks:
- name: Enable SSH agent forwarding
lineinfile:
dest: ~/.ssh/config
line: " ForwardAgent yes"
insertafter: "Host *"
- name: Test SSH agent forwarding
hosts: all
tasks:
- name: Test SSH connection
command: ssh -T git@github.com
register: ssh_output
ignore_errors: yes
- name: Display SSH output
debug:
var: ssh_output.stderr_lines
上述示例代码将在所有主机上配置SSH代理,并测试连接到GitHub。如果成功连接,则在debug输出中显示SSH输出。
请注意,为了使SSH代理工作正常,需要满足以下条件:
ssh-agent
进程正在运行通过上述步骤,您应该能够解决Ansible用户无法通过网络共享进行身份验证的问题。