Following are the solution of "fatal: [localhost] => SSH Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).":
Video:
Create the files likewise mention bellow:
[root@vagrant-centos65 vagrant]# pwd/home/vagrant
[root@vagrant-centos65 vagrant]# ls -R
.:
hosts provision.sh tutorialbyexample.yml
or
[root@vagrant-centos65 vagrant]# ls -ltr
total 12
-rw-r--r-- 1 root root 342 Feb 11 21:50 hosts
-rw-r--r-- 1 root root 854 Feb 11 21:50 tutorialbyexample.yml
-rwxrwxrwx 1 root root 141 Feb 11 21:55 provision.sh
Add the contents in files like:
vi hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
[local-1]
localhost
Save the file.
vi tutorialbyexample.yml
# This yml file is used for
# Created by: Vinod Kumar
##################################################################
---
- hosts: local-1
sudo: yes
vars:
##################################################################
# This is the task section for all activities
##################################################################
tasks:
# #############################################################
# This is for host checking alive or not
# #############################################################
- name: 1. Check that the servers alive
action: ping
# #############################################################
vi provision.sh
cp -rf /home/vagrant/hosts /tmp
chmod -x /tmp/hosts
sudo ansible-playbook -vvvv -i /tmp/hosts /home/vagrant/tutorialbyexample.yml -u root -k
Run it provision.sh and provide the password.
[root@vagrant-centos65 vagrant]# ./provision.sh
SSH password:
PLAY [local-1] ****************************************************************
GATHERING FACTS ***************************************************************
<localhost> ESTABLISH CONNECTION FOR USER: root
<localhost> REMOTE_MODULE setup
<localhost> EXEC sshpass -d4 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 localhost /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1455228622.12-15128046797845 && echo $HOME/.ansible/tmp/ansible-tmp-1455228622.12-15128046797845'
<localhost> PUT /tmp/tmpQBbGli TO /root/.ansible/tmp/ansible-tmp-1455228622.12-15128046797845/setup
<localhost> EXEC sshpass -d4 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 localhost /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=oxmfsjkdmwkijahkrvcznamgmnbjwubl] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-oxmfsjkdmwkijahkrvcznamgmnbjwubl; LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1455228622.12-15128046797845/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1455228622.12-15128046797845/ >/dev/null 2>&1'"'"''
ok: [localhost]
TASK: [1. Check that the servers alive] ***************************************
<localhost> ESTABLISH CONNECTION FOR USER: root
<localhost> REMOTE_MODULE ping
<localhost> EXEC sshpass -d7 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 localhost /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1455228644.99-208418987783009 && echo $HOME/.ansible/tmp/ansible-tmp-1455228644.99-208418987783009'
<localhost> PUT /tmp/tmpyLzvHg TO /root/.ansible/tmp/ansible-tmp-1455228644.99-208418987783009/ping
<localhost> EXEC sshpass -d7 ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 localhost /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=bllzznvgwbdnusqwnapssctiakzilnke] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-bllzznvgwbdnusqwnapssctiakzilnke; LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1455228644.99-208418987783009/ping; rm -rf /root/.ansible/tmp/ansible-tmp-1455228644.99-208418987783009/ >/dev/null 2>&1'"'"''
ok: [localhost] => {"changed": false, "ping": "pong"}
PLAY RECAP ********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
Hopping your issue got resolved..if not then put you details.....
Grt...example and video for Ansible, I was facing this issue from long time, tried several way finally resolved by your video by bellow line....
ReplyDeletevi provision.sh
cp -rf /home/vagrant/hosts /tmp
chmod -x /tmp/hosts
sudo ansible-playbook -vvvv -i /tmp/hosts /home/vagrant/tutorialbyexample.yml -u root -k
Thanks for your response.......Ansible will rule devops....Cheers Team!!!
DeleteThankssssssssssssssss :D
ReplyDeletefatal: [localhost] => SSH Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). was causing for us from long time and finally resolved. Well done and Thank you...
ReplyDelete