I’m trying to get Ansible up and running on a windows environment, which I know is not technically supported. However, using the following guide, http://dhorbach.blogspot.com/2013/08/working-with-ansible-in-eclipse-and.html, which took about 15 - 20 minutes, I was able to start running playbooks from my windows machine.
But, I also need to manage windows environments as well, not just run playbooks from a windows machine. After getting SSHD up and running on a target system, I tried executing the following command:
$ ansible -c ssh WindowsTestServer -a “/usr/bin/whoami.exe”
But, it threw an error:
msaltzmanw7.bbbb.net | FAILED >> {
“failed”: true,
“msg”: "/usr/bin/python: can’t open file ‘/home/msaltzman/.ansible/tmp/ansible-tmp-1392324304.91-246447835237283/command’,
“parsed”: false
}
I tracked it down to the fact that the tmp directories that the modules, playbooks, etc. use on the remote machine weren’t getting created prior to trying to move the required modules and code into said temp directory. I’m not sure if this is the best way to fix it, but I altered ansible/runner/connection_plugins/ssh.py to create the directory first using sftp:
def put_file(self, in_path, out_path, out_dir):
‘’’ transfer a file from local to remote ‘’’
vvv(“PUT %s TO %s” % (in_path, out_path), host=self.host)
if not os.path.exists(in_path):
raise errors.AnsibleFileNotFound(“file or module does not exist: %s” % in_path)
cmd = self._password_cmd()
host = self.host
if self.ipv6:
host = ‘[%s]’ % host
if C.DEFAULT_SCP_IF_SSH:
cmd += [“scp”] + self.common_args
cmd += [in_path,host + “:” + pipes.quote(out_path)]
indata = None
else:
cmd += [“sftp”] + self.common_args + [host]
mkdir = “mkdir %s” % ( out_dir )
indata = “put %s %s\n” % (pipes.quote(in_path), pipes.quote(out_path))
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self._send_password()
stdout, stderr = p.communicate( mkdir )
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self._send_password()
stdout, stderr = p.communicate(indata)
if p.returncode != 0:
raise errors.AnsibleError(“failed to transfer file to %s:\n%s\n%s” % (out_path, stdout, stderr))
I wanted to check if this was a good way to solve the problem before I submitted a pull request for it. What do you think?