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

**URL:** <https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [July 3, 2016, 11:53am UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911 "2016-07-03T11:53:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Abyankar](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Anand\_Abyankar](https://forum.ansible.com/u/Anand_Abyankar)\
**Post date:** [July 3, 2016, 11:53am UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911/1 "2016-07-03T11:53:54Z")

</div>

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](mailto:Das@192.168.111.113)”  
this created key and copied it to remote machine by  
ssh-copy-id [Das@192.168.111.113](mailto: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

---

<div class="post-metadata">

**Author:** ![Leandro\_Penz1](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@Leandro\_Penz1](https://forum.ansible.com/u/Leandro_Penz1)\
**Post date:** [July 4, 2016, 2:50am UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911/2 "2016-07-04T02:50:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rene\_Moser](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rene\_Moser](https://forum.ansible.com/u/Rene_Moser)\
**Post date:** [July 4, 2016, 5:20am UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911/3 "2016-07-04T05:20:27Z")

</div>

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](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é

---

<div class="post-metadata">

**Author:** ![Anand\_Abyankar](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Anand\_Abyankar](https://forum.ansible.com/u/Anand_Abyankar)\
**Post date:** [July 8, 2016, 6:56pm UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911/4 "2016-07-08T18:56:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sachidananda\_sahu](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@sachidananda\_sahu](https://forum.ansible.com/u/sachidananda_sahu)\
**Post date:** [April 11, 2017, 5:36am UTC](https://forum.ansible.com/t/create-directory-in-etc-and-copy-files-without-password-using-ansible/21911/5 "2017-04-11T05:36:23Z")

</div>

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
