代码之家  ›  专栏  ›  技术社区  ›  kboom

Kubespray与堡垒和自定义SSH端口+代理转发

  •  0
  • kboom  · 技术社区  · 6 年前

    1 回复  |  直到 5 年前
        1
  •  2
  •   mdaniel    6 年前

    始终如此,因为您可以在三个不同的级别配置它:通过主机用户的 ~/.ssh/config ,通过整个剧本 group_vars ,或作为内联配置(即在命令行或清单文件中)。

    ssh配置很简单:

    Host 1.2.* *.example.com # or whatever pattern matches the target instances
      ProxyJump someuser@some-bastion:1234
      # and then the Agent should happen automatically, unless you mean
      # ForwardAgent yes
    

    接下来我将与内联配置对话,因为它有点简单:

    ansible-playbook -i whatever \
        -e '{"ansible_ssh_common_args": "-o ProxyJump=\"someuser@jump-host:1234\""}' \
        cluster.yaml
    

    或者以同样的方式通过库存:

    master-host-0 ansible_host=1.2.3.4 ansible_ssh_common_args="-o ProxyJump='someuser@jump-host:1234'"
    

    组变量 ,可以添加到现有的 group_vars/all.yml ,或者如果它不存在,则创建 组变量 all.yml 作为包含清单文件的目录的子目录的文件

    如果您有比您希望在inventory/command-line/group-vars中编码的更复杂的ssh配置,您还可以通过 ansible_ssh_extra_args 变量:

    ansible-playbook -e '{"ansible_ssh_extra_args": "-F /path/to/special/ssh_config"}' ...
    
        2
  •  0
  •   Chris Stryczynski    5 年前

    ~/.ssh/config 成为:

    Host 10.40.45.102
      ForwardAgent yes
      User root
      ProxyCommand ssh -W %h:%p -p 44057 root@example.com
    
    Host 10.40.45.104
      ForwardAgent yes
      User root
      ProxyCommand ssh -W %h:%p -p 44058 root@example.com
    

    10.40.* 是内部IP。