Create directory in /etc/ and copy files without password using ansible

I an new to ansible. I may be saying something which is completely wrong.

I created VM using KVM, both remote and local are running on Ubuntu 16.0.4

Now I configured ansible by creating a key as
ssh-keygen -t rsa -b 4096 -C “Das@192.168.111.113
this created key and copied it to remote machine by
ssh-copy-id Das@192.168.111.113
now I tested ssh is working, it is working fine.

I added remote machine’s address in /etc/ansible/hosts under [DDAS] group.

now I can ping to remote machine using ansible. Then I wrote Playbook to copy file. I is working fine to copy files to /home/Das1/ only. I mean, I can copy files to location which do not need root permission.

My current requirement is that I want to copy some files from local to host to location something like /etc/new

ALSO

I want to run a service which I have written but can not start as ansible says something like “:interactinve password required”.

I am configuring ansible/ssh in wrong way.

any help is highly appreciated.

Thanks
Anand

I guess you have to setup the user Das in the sudoers file, call ansible with “-K” and provided the sudo password.

Hi Anand

You are on the right track.

You have basically two options:

Configure the das user to be able to use sudo (with or without password)
or you copy the ssh key to the root's authorized_keys file so you are
able to ssh to the root account.

For the first option, it would be necessary to set "become: yes" in your
playbooks and always pass the password if you didn't make it password
less. Also see http://docs.ansible.com/ansible/become.html

For the second option, just use "remote_user: root" in your playbooks
after you have copied the ssh public key into /root/.ssh/authorized_keys.

Regards
René

Thank you very much Rene Moser.

It worked for me. I simply sudo by sudo visudo and added NOPASSWD with my log in id. Its your suggestion that made my work reach to completion.

Thanks Again,

Anand

Hello Mal and Anand

I have similar requirement, but i am very much confused with this become and sudo and user option.

With this point of yours "Configure the das user to be able to use sudo (with or without password) "
I guess u want to add das user to the /etc/sudoers file for making password less.

So how i can i write a task which will do this for me, i mean editing the /etc/sudoers file and add the user as suders list.

So that later point of time all sudo command with sudo:yes, user: will workfine.

What my doubt is to edit the file itself i need sudo, so how can i achive it. I am really get confised with become, sudo, sudo_user, become_user and user,

Can you tell how can i achieve this.

Thanks
Sachidananda