Arbab Nazar
Arbab Nazar

Reputation: 23801

template transfer error in ansible 2.0

I have a really simple role, that work well in ansible 1.9.4 but when I run the same role using ansible 2.0, I got an error during template transfer. Is something change for template module in ansible 2.0?

My role layout:

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

I have test the connectivity with the remote server with ansible ping module:

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

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

Here is the task on which I am getting an error:

- 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

Here is an error:

<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

Upvotes: 0

Views: 1229

Answers (2)

Zandao
Zandao

Reputation: 371

Since you are not using SSH keys to authenticate, you must try running "export ANSIBLE_SCP_IF_SSH=y" before running ansible-playbook with -vvv option.

If it still doesn't work and the error message changes, please post the new error message so we can continue from there to find a solution to your problem.

Upvotes: 2

Petro026
Petro026

Reputation: 1309

This looks oddly familiar to something I saw over a year ago with paramiko selecting SFTP for file transport. Try running your playbook with "-c ssh" to see if that fixes your problem

Upvotes: 0

Related Questions