Saturday, October 23, 2021

[SOLVED] Not able to run ansible playbook in ec2(host machine) to Mac(target machine)

Issue

My mac machine is communicating with an ec2 instance, SSH connection is established and when it's pinged ,I am getting a response as "pong", but when I run playbook facing below issue.

but when I run playbook getting below error:

PLAY [macserver] ***************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [X.X.X.X]: FAILED! => {"msg": "Missing sudo password"}

PLAY RECAP *********************************************************************
X.X.X.X : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

running the playbook as ec2-user, also just to check if issue is with ec2-user added new user as "ansible" in my linux ec2 instance and started running playbook, but still same issue is persisting. Also I have added ec2-user in sudoers file.

I tried alternative method to run playbook as specified below:

"ansible-playbook paybook.yml -k -K"

command to give password and run playbook, in that scenario facing incorrect sudo password error. Whereas the password created for root, ec2-user and ansible all are same. I am not able to figure out what and where I am missing, Can anyone help me with this?


Solution

You are connecting your Mac from EC2. "Missing sudo password" is not of root/ec2-user of EC2 server but of the Mac. You need to provide username/password/sudo access etc of target machine

Regarding use of "ec2-user". You can continue with ec2-user or ubuntu user, which is a default user for EC2 instance. However, it is always a good practice to create a new user(s) with restricted accesses and delete the default user.



Answered By - saurabh14292