ansible 2.0中的模板传输错误

时间:2016-01-28 17:34:38

标签: ansible ansible-playbook ansible-2.x

我有一个非常简单的角色,在ansible 1.9.4中运行良好但是当我使用ansible 2.0运行相同的角色时,我在模板传输过程中遇到了错误。在ansible 2.0中模板模块有什么变化吗?

我的角色布局:

.
|-- handlers
|   `-- main.yml
|-- tasks
|   `-- main.yml
|-- templates
|   |-- etc_default_isc-dhcp-server.j2
|   `-- etc_dhcp_dhcpd.conf.j2
`-- vars
    `-- main.yml

我已经使用ansible ping模块测试了与远程服务器的连接:

ansible -m ping all -u vagrant -k
SSH password:

192.168.33.10 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

以下是我收到错误的任务:

- name: Write the modified 'isc-dhcp-server' file
   template: 
    src: templates/etc_default_isc-dhcp-server.j2 
    dest: /etc/default/isc-dhcp-server 
    backup: yes

这是一个错误:

<192.168.33.10> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.33.10> SSH: EXEC sshpass -d25 ssh -C -vvv -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o User=vagrant -o ConnectTimeout=10 -tt 192.168.33.10 '( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1454001802.16-105340173307790 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1454001802.16-105340173307790 )" )'
<192.168.33.10> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.33.10> SSH: EXEC sshpass -d25 ssh -C -vvv -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o User=vagrant -o ConnectTimeout=10 -tt 192.168.33.10 '/bin/sh -c '"'"'sudo -HE -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-phyquqhgvqgsigneasanzgmfyvgsoyby; rc=flag; [ -r /etc/default/isc-dhcp-server ] || rc=2; [ -f /etc/default/isc-dhcp-server ] || rc=1; [ -d /etc/default/isc-dhcp-server ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != "xflag" ] && echo "${rc}  "/etc/default/isc-dhcp-server && exit 0; (python -c '"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();
afile = open("'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'/etc/default/isc-dhcp-server'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'", "rb")
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
    hasher.update(buf)
    buf = afile.read(BLOCKSIZE)
afile.close()
print(hasher.hexdigest())'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"' 2>/dev/null) || (python -c '"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'import sha; BLOCKSIZE = 65536; hasher = sha.sha();
afile = open("'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'/etc/default/isc-dhcp-server'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'", "rb")
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
    hasher.update(buf)
    buf = afile.read(BLOCKSIZE)
afile.close()
print(hasher.hexdigest())'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"' 2>/dev/null) || (echo '"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'0  '"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'/etc/default/isc-dhcp-server)'"'"'"'"'"'"'"'"''"'"''
<192.168.33.10> PUT /var/folders/rq/yhlwx3c971x6p88qwmvhpg600000gn/T/tmpb1lTNM TO /home/vagrant/.ansible/tmp/ansible-tmp-1454001802.16-105340173307790/source
<192.168.33.10> SSH: EXEC sshpass -d25 sftp -b - -C -vvv -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o User=vagrant -o ConnectTimeout=10 '[192.168.33.10]'
fatal: [192.168.33.10]: UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}

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

2 个答案:

答案 0 :(得分:2)

由于您没有使用SSH密钥进行身份验证,因此必须尝试运行&#34;导出ANSIBLE_SCP_IF_SSH = y&#34;在使用-vvv选项运行ansible-playbook之前。

如果仍然无法正常工作且错误消息发生变化,请发布新的错误消息,以便我们可以从那里继续找到问题的解决方案。

答案 1 :(得分:0)

这看起来很奇怪我一年前看到的事情,paramiko选择SFTP进行文件传输。尝试使用&#34; -c ssh&#34;运行您的Playbook看看是否能解决你的问题