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: [email protected]: 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:

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.

2 Answers 2


You run the command with the user shishir9159_gmail_com but the error shows [email protected]: 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?

  • 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 for user shishir9159. I don't know how to change this... Dec 23, 2019 at 5:03

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.