我有一个剧本,是由另一本剧本通过以下包含设置启动的。
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作为单独的剧本运行时,会添加标头并将相同的主机包含在清单文件中。
- 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命令?
答案 0 :(得分:0)
。
- 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
答案 1 :(得分: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,并且当启用collect_facts时,它将尝试将结果json SFTP返回源服务器。 谢谢@Vladimir Botka,您的评论为我指明了正确的方向