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

224 views
Skip to first unread message

Anand Abyankar

unread,
Jul 3, 2016, 7:53:54 AM7/3/16
to Ansible Development
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 "D...@192.168.111.113"
this created key and copied it to remote machine by 
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

Leandro Penz

unread,
Jul 3, 2016, 10:50:37 PM7/3/16
to Anand Abyankar, Ansible Development
I guess you have to setup the user Das in the sudoers file, call ansible with "-K" and provided the sudo password.


--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rene Moser

unread,
Jul 4, 2016, 1:24:52 AM7/4/16
to ansibl...@googlegroups.com
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é
> --
> You received this message because you are subscribed to the Google
> Groups "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ansible-deve...@googlegroups.com
> <mailto:ansible-deve...@googlegroups.com>.

Anand Abyankar

unread,
Jul 8, 2016, 2:56:52 PM7/8/16
to Ansible Development
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

sachidananda sahu

unread,
Apr 11, 2017, 1:36:23 AM4/11/17
to Ansible Development
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: <Specific 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
Reply all
Reply to author
Forward
0 new messages