gpt4 book ai didi

ansible - 是否可以在 list 文件中添加ansible_ssh_common_args

转载 作者:行者123 更新时间:2023-12-04 13:26:15 25 4
gpt4 key购买 nike

我想使用ansible_ssh_common_args的ProxyCommand跳转/SSH堡垒主机。
ansible服务器:10.10.149.2
网关/堡垒主机:10.10.149.70
主机连接:10.32.32.190
所以我的目标是从10.10.149.2的低谷10.10.149.70(ssh隧道)连接10.32.32.190

ansible --version
ansible 2.1.0.0

我的库存:

[local]
10.10.149.2

[Private]
10.32.32.190

[Private:vars]
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q root@10.10.149.70"'

pingtest.yml:
---
- hosts: Private
tasks:
- name: test connection
ping:
register: ping1
- debug: var=ping1

面临的问题:
 fatal: [10.32.32.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}

因此,我怀疑 list 文件中的ansible_ssh_common_args支持如何。我不想使用ssh.config文件。

日志:
   [root@mavosdsc ansible]# ansible-playbook -i inventory pingtest.yml -e "user=root" --ask-pass -vvvv
Using /etc/ansible/ansible.cfg as config file
SSH password:
Loaded callback default of type stdout, v2.0

PLAYBOOK: pingtest.yml *********************************************************
1 plays in pingtest.yml

PLAY [Private] *****************************************************************

TASK [setup] *******************************************************************
<10.32.32.190> ESTABLISH SSH CONNECTION FOR USER: None
<10.32.32.190> SSH: EXEC sshpass -d12 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 10.32.32.190 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1469788026.71-124524328003439 `" && echo ansible-tmp-1469788026.71-124524328003439="` echo $HOME/.ansible/tmp/ansible-tmp-1469788026.71-124524328003439 `" ) && sleep 0'"'"''
fatal: [10.32.32.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
to retry, use: --limit @pingtest.retry

PLAY RECAP *********************************************************************
10.32.32.190 : ok=0 changed=0 unreachable=1 failed=0

最佳答案

问题在这里:ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q root@10.10.149.70"'将“:”替换为“=”,并这样写:ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q root@10.10.149.70"'为了帮助他人,请记住您的库存文件是一个“.ini”文件。
'.ini'文件,例如ansible.cfg,使用'='分配变量,因为'yaml'文件使用':'。

关于ansible - 是否可以在 list 文件中添加ansible_ssh_common_args,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38651791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com