Ansible包括播放任务获取错误“无法打开SFTP连接”

问题描述 投票:0回答:2

我有一个由另一个使用include设置启动的剧本,如下所示。

parent.yml

- hosts: localhost
  gather_facts: False

  tasks:
   - add_host:
       name: "{{ item.value['hostname'] }}"
       ansible_host: "{{ item.value['oob_ip'] }}"
       ansible_user: "{{ servers.web_servers.vars.ilousername }}"
       ansible_ssh_pass: "{{ servers.web_servers.vars.ilopassword }}"
       group: ilohosts
- hosts: ilohosts 
  tasks:
    - include: collect_mac.yml

collect_mac.yml

#- set_fact: 
#    ansible_ssh_pass: "{{ servers.web_servers.vars.ilopassword }}"

- name: collect MAC address
  raw: "racadm getsysinfo"
  register: eth_info

剩下的yml我已经脱光了。由于其少数正则表达式可以获取MAC地址。

问题是当我将collect_mac.yml作为单独的playbook运行时添加标题并在库存文件中包含相同的主机。

- name: collect mac
  hosts: hosts
  remote_user: root
  gather_facts: False

它运行没有问题。但是当它通过parent.yml运行时,我收到以下错误

{"msg": "failed to open a SFTP connection (Garbage packet received)"} 

为什么ansible尝试打开SFTP会话而不是SSH并运行raw命令?

ansible
2个回答
0
投票
  • 列出hostvars
  • 仔细检查参数是否正确
  • 并可能修复add_host的参数

.

- hosts: ilohosts 
  tasks:
    - debug: var=hostvars

例如,下面的剧本按预期工作。

- hosts: localhost
  tasks:
    - add_host:
        name: test_01
        ansible_host: 10.1.0.51
        groups: ilohosts
- hosts: ilohosts
  tasks:
    - raw: hostname
      register: info
    - debug:
        var: info.stdout

0
投票

发现了实际问题。它的gather_facts引起了这个问题。一旦我修改了parent.yml中调用child.yml的部分就像这样错误就消失了。

- hosts: localhost
  gather_facts: False

  tasks:
   - add_host:
     name: "{{ item.value['hostname'] }}"
     ansible_host: "{{ item.value['oob_ip'] }}"
     ansible_user: "{{ servers.web_servers.vars.ilousername }}"
     ansible_ssh_pass: "{{ servers.web_servers.vars.ilopassword }}"
     group: ilohosts
- hosts: ilohosts
  gather_facts: False 
  tasks:
   - include: collect_mac.yml

我认为这是因为我正在连接的服务器不支持SFTP,并且当gather_facts启用时,它会尝试将结果json SFTP返回到源服务器。谢谢@Vladimir Botka,你的评论指出了我正确的方向

© www.soinside.com 2019 - 2024. All rights reserved.