Answers: <p>I solved the problem by adding <code>ansible_ssh_user</code> and <code>ansible_ssh_pass</code> at the hosts file. This post contain the solution.
  <a href="https://stackoverflow.com/questions/37213551/ansible-ssh-connection-fail?rq=1">https://stackoverflow.com/questions/37213551/ansible-ssh-connection-fail?rq=1</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-24T06:45:27.513Z
Answers: 2019-12-24T06:45:27.513Z
Answers: noobmaster69
Answers: <p>You run the command with the user <code>shishir9159_gmail_com</code> but the error shows <code>shishir9159@35.202.219.6: Permission denied</code> ... seems like the <code>_gmail_com</code> portion of the username is truncated. Can you try setting the <code>ansible_user</code> config parameter in your inventory file or playbook rather than passing it on via the CLI? </p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-23T05:03:18.773Z
Answers: I tried as ansible_user and ssh_user too in "ansible.cfg". But with "-vvvv" parameter (that shows verbose in details), it's always showing Connecting to host 35.202.219.6 for user shishir9159. I don't know how to change this...
Answers: noobmaster69
Answers: CC BY-SA 4.0
Answers: 2019-12-22T15:45:09.813Z
Answers: 2019-12-22T15:45:09.813Z
Answers: Jorn
Body: <p>I'm trying to automate google cloud virtual instances remotely only using external ip addresses of virtual machines. I can ssh into the virtual machines using command line with user name <code>shishir9159_gmail_com</code> . But If I use any ansible commands like this:</p>
  
  <pre><code>ansible -i hosts -u shishir9159_gmail_com --private-key=~/.ssh/google_compute_engine -m ping all
  </code></pre>
  
  <p>and it results in this following error:</p>
  
  <pre><code>"msg": "Failed to connect to the host via ssh: shishir9159@35.202.219.6: Permission denied (publickey,gssapi-keyex,gssapi-with-mic)."
  </code></pre>
  
  <p>I've used some parameters in my ansible.cfg:</p>
  
  <pre><code>host_key_checking = False
  ssh_args = -o ControlMaster=no
  </code></pre>
  
  <p>But I don't think they do much of a help according to this post:<br>
  <a href="https://serverfault.com/questions/929222/ansible-where-do-preferredauthentications-ssh-settings-come-from">https://serverfault.com/questions/929222/ansible-where-do-preferredauthentications-ssh-settings-come-from</a></p>
  
  <p>And I tried many methods and recommendations. I have a service account but it doesn't seem to me necessary for this simple ping command.</p>
  
Tags: <ansible><google-cloud-platform><ssh>
Title: Running Automation on Google Cloud Virtual Instances using Ansible
UserDisplayName: noobmaster69
ThreadText: # Running Automation on Google Cloud Virtual Instances using Ansible
  
  (Asked by: username_0 on 2019-12-22)
  
  I'm trying to automate google cloud virtual instances remotely only using external ip addresses of virtual machines. I can ssh into the virtual machines using command line with user name `shishir9159_gmail_com` . But If I use any ansible commands like this:
  
  ```
  ansible -i hosts -u shishir9159_gmail_com --private-key=~/.ssh/google_compute_engine -m ping all
  
  ```
  
  and it results in this following error:
  
  ```
  "msg": "Failed to connect to the host via ssh: shishir9159@35.202.219.6: Permission denied (publickey,gssapi-keyex,gssapi-with-mic)."
  
  ```
  
  I've used some parameters in my ansible.cfg:
  
  ```
  host_key_checking = False
  ssh_args = -o ControlMaster=no
  
  ```
  
  But I don't think they do much of a help according to this post:  
  <https://serverfault.com/questions/929222/ansible-where-do-preferredauthentications-ssh-settings-come-from>
  
  And I tried many methods and recommendations. I have a service account but it doesn't seem to me necessary for this simple ping command.
  
  **Tags:** ansible, google-cloud-platform, ssh
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-12-24. Score: 0 | Accepted answer
  
  I solved the problem by adding `ansible_ssh_user` and `ansible_ssh_pass` at the hosts file. This post contain the solution.
  <https://stackoverflow.com/questions/37213551/ansible-ssh-connection-fail?rq=1>
  
  
  ---
  
  ### Answer by username_1 on 2019-12-22. Score: 2
  
  You run the command with the user `shishir9159_gmail_com` but the error shows `shishir9159@35.202.219.6: Permission denied` ... seems like the `_gmail_com` portion of the username is truncated. Can you try setting the `ansible_user` config parameter in your inventory file or playbook rather than passing it on via the CLI?
  
  > **Comments:**
  > **username_0**: I tried as ansible_user and ssh_user too in "ansible.cfg". But with "-vvvv" parameter (that shows verbose in details), it's always showing Connecting to host 35.202.219.6 for user shishir9159. I don't know how to change this...  
  
  ---
  
  