ssh - Ansible 使用密码配置跳转主机
问题描述
我有三个主机 - A、B 和 C,其中 A 是我的 Ansible 主机,C 是需要通过 B 访问的目标主机。
作为我的清单文件的一部分,我拥有 B 和 C 主机的详细信息,如下所示:
b:
ansible_host: "{{b_ip}}"
ansible_port: 22
ansible_user: root
ansible_password: password
c:
ansible_host: "{{c_ip}}"
ansible_port: 22
ansible_user: root
ansible_password: password
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q root@{{b_ip}}"'
我们如何配置 ansible 以使用清单文件中 B 和 C 主机中提到的密码,而不是使用 ~/.ssh/config 文件中的任何其他配置?
解决方案
没有直接的方法可以将跳转主机的密码作为 ProxyCommand 的一部分提供。
所以,我最终做了以下事情:
# Generate SSH keys for the Ansible Host A
- hosts: localhost
become: false
tasks:
- name: Generate the localhost ssh keys
openssh_keypair:
path: ~/.ssh/id_rsa
force: no
# Copy the host keys of Ansible host to the jump host into the authorized keys of # the ssh to ensure that no password is prompted while logging into jump host A
- hosts: b
become: false
tasks:
- name: Create ssh directory if not exists
file:
path: /home/root/.ssh
state: directory
- name: Copy SSH keys into host B
copy:
src: ~/.ssh/id_rsa.pub
dest: /home/root/.ssh/authorized_keys
force: yes
推荐阅读
- javascript - 想要在函数完成后让 DB 调用等待
- c# - WPF将值从TextBlock发送到方法
- ruby-on-rails - 为什么我不能用参数创建对象?
- android - 为什么我的 ImageView 不显示图像?
- javascript - 避免在 ParcelJS 上的 HTML 文件中重命名 JS 变量
- tomcat - 露天 SMTPAddressFailedException 553 错误
- flutter - 如何在彩色矩形内制作透明圆圈
- c++ - 在程序开始时使用 ofstream 擦除 C++ 读取文件
- python - 以不同的方式添加图例和颜色每个条
- javascript - 如何强制用户选择至少一个选项以转到下一页 Vue JS