<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.4.4</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Oracle Enterprise Linux 5.9</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">I've encountered an error in a file module task running on OEL 5.9 that doesn't seem to have the same issue running on CentOS 5.x:</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: ensure /mnt/s3/quantumcloud exists
  file: path=/mnt/s3/quantumcloud owner=root group=root mode=0755 state=directory
  sudo: True"><pre class="notranslate"><code class="notranslate">- name: ensure /mnt/s3/quantumcloud exists
  file: path=/mnt/s3/quantumcloud owner=root group=root mode=0755 state=directory
  sudo: True
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">If directory exists, a no change response</p>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [hostXXX.domainXXX] =&gt; failed to parse:
SUDO-SUCCESS-szammrqwhpjmcnhwvqnlnvdrpggamxsj
Traceback (most recent call last):
  File &quot;/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file&quot;, line 1378, in ?
    main()
  File &quot;/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file&quot;, line 269, in main
    changed = module.set_directory_attributes_if_different(file_args, changed)
  File &quot;/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file&quot;, line 833, in set_directory_attributes_if_different
    changed = self.set_mode_if_different(
  File &quot;/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file&quot;, line 796, in set_mode_if_different
    raise e
OSError: [Errno 5] Input/output error: '/mnt/s3/quantumcloud'"><pre class="notranslate"><code class="notranslate">fatal: [hostXXX.domainXXX] =&gt; failed to parse:
SUDO-SUCCESS-szammrqwhpjmcnhwvqnlnvdrpggamxsj
Traceback (most recent call last):
  File "/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file", line 1378, in ?
    main()
  File "/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file", line 269, in main
    changed = module.set_directory_attributes_if_different(file_args, changed)
  File "/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file", line 833, in set_directory_attributes_if_different
    changed = self.set_mode_if_different(
  File "/home/jrosengren/.ansible/tmp/ansible-1392144575.3-31016918420544/file", line 796, in set_mode_if_different
    raise e
OSError: [Errno 5] Input/output error: '/mnt/s3/quantumcloud'
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ssh.py from plugins/connection module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Centos 7 with Python 3.4.3</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When you try lo login into a server, the user name generated is not valid. There is a duplicated call to the <code class="notranslate">to_bytes</code> method when applying the <code class="notranslate">ANSIBLE_REMOTE_USER</code>.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">When we try to make a ping to our openstack group:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible openstack  -m ping "><pre class="notranslate"><code class="notranslate">ansible openstack  -m ping 
</code></pre></div>
<p dir="auto">Where our <code class="notranslate">/etc/ansible/hosts</code> is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[openstack]
bootstrap ansible_host=10.200.0.130 ansible_user=cloud-user ansible_ssh_private_key_file=/home/uarrien/Documents/stratio/certs/testKeyPair.pem"><pre class="notranslate"><code class="notranslate">[openstack]
bootstrap ansible_host=10.200.0.130 ansible_user=cloud-user ansible_ssh_private_key_file=/home/uarrien/Documents/stratio/certs/testKeyPair.pem
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bootstrap | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;ping&quot;: &quot;pong&quot;
}"><pre class="notranslate"><code class="notranslate">bootstrap | SUCCESS =&gt; {
    "changed": false, 
    "ping": "pong"
}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bootstrap | UNREACHABLE! =&gt; {
    &quot;changed&quot;: false,
    &quot;msg&quot;: &quot;Failed to connect to the host via ssh.&quot;,
    &quot;unreachable&quot;: true
}"><pre class="notranslate"><code class="notranslate">bootstrap | UNREACHABLE! =&gt; {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
</code></pre></div>
<p dir="auto">If we execute the command verbose:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="No config file found; using defaults
Using module file /root/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ansible/modules/core/system/ping.py
&lt;10.200.0.130&gt; ESTABLISH SSH CONNECTION FOR USER: cloud-user
&lt;10.200.0.130&gt; SSH: EXEC ssh -q -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile=&quot;/home/uarrien/Documents/stratio/certs/testKeyPair.pem&quot;' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User=b'&quot;'&quot;'cloud-user'&quot;'&quot;'' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 10.200.0.130 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1475234121.3512669-205100461461219 `&quot; &amp;&amp; echo ansible-tmp-1475234121.3512669-205100461461219=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1475234121.3512669-205100461461219 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
bootstrap | UNREACHABLE! =&gt; {
    &quot;changed&quot;: false,
    &quot;msg&quot;: &quot;Failed to connect to the host via ssh.&quot;,
    &quot;unreachable&quot;: true
}"><pre class="notranslate"><code class="notranslate">No config file found; using defaults
Using module file /root/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ansible/modules/core/system/ping.py
&lt;10.200.0.130&gt; ESTABLISH SSH CONNECTION FOR USER: cloud-user
&lt;10.200.0.130&gt; SSH: EXEC ssh -q -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/uarrien/Documents/stratio/certs/testKeyPair.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User=b'"'"'cloud-user'"'"'' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 10.200.0.130 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1475234121.3512669-205100461461219 `" &amp;&amp; echo ansible-tmp-1475234121.3512669-205100461461219="` echo $HOME/.ansible/tmp/ansible-tmp-1475234121.3512669-205100461461219 `" ) &amp;&amp; sleep 0'"'"''
bootstrap | UNREACHABLE! =&gt; {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
</code></pre></div>
<p dir="auto">We can see that the User is not well formed:</p>
<p dir="auto"><code class="notranslate">'User=b'"'"'cloud-user'"'"''</code></p>
<p dir="auto">To fix this, we should remove the <code class="notranslate">to_bytes</code> call from the following line:</p>
<p dir="auto"><a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py#L197">https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/ssh.py#L197</a></p>
<p dir="auto">We have tested with the following line of code and it works properly:</p>
<p dir="auto"><code class="notranslate">("-o", "User={0}".format(self._play_context.remote_user))</code></p>