# Ansible: Creating a file on Local machine fails

**URL:** <https://forum.ansible.com/t/ansible-creating-a-file-on-local-machine-fails/25161>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [August 1, 2017, 10:23pm UTC](https://forum.ansible.com/t/ansible-creating-a-file-on-local-machine-fails/25161 "2017-08-01T22:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor1](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Victor1](https://forum.ansible.com/u/Victor1)\
**Post date:** [August 1, 2017, 10:23pm UTC](https://forum.ansible.com/t/ansible-creating-a-file-on-local-machine-fails/25161/1 "2017-08-01T22:23:55Z")

</div>

Hi All,

I am new to ansible and i am not sure about the become and become\_user usage and looks like that is the cause of my problem.  
looking for a simple solution.

I have to create a simple results.txt file locally on the control machine( ubuntu machine) and log the success and failure based upon the pass/fail test cases executed through different roles.  
In my host file i have created the entry for localhost as below

```auto
[localhost]
127.0.0.1 ansible_connection=local ansible_ssh_user=XXXX ansible_ssh_pass=XXXXXX

ansible_ssh_user is my ubuntu machine user( Question: Do I necessarily need to give the user and password here?)

now i have a separate role for creating a file in /etc/ansible directory as below.

---
      - name: Create the results file
         file:
            path: /etc/ansible/results.txt
            state: touch
            mode: 0777

I am calling the above role from playbook .yml file as below.

 ---

- hosts: localhost
  roles:
   - Local_File

when i execute the playbook I always get this error.

 ansible-playbook vcenter_snaprestore.yml
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting

PLAY [localhost] ********************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [Local_File : Create the results file] *****************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IOError: [Errno 13] Permission denied: '/etc/ansible/results.txt'
fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_te7z37/ansible_module_file.py\", line 480, in <module>\n main()\n File \"/tmp/ansible_te7z37/ansible_module_file.py\", line 451, in main\n open(b_path, 'wb').close()\nIOError: [Errno 13] Permission denied: '/etc/ansible/results.txt'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
*************************************************************************************

And since it shows permission issue, I include become: yes in the role as below

- hosts: localhost
  become: yes
  roles:
   - Local_File

then i get the following error:
vmisra@ubuntu:/etc/ansible$ ansible-playbook vcenter_snaprestore.yml
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting

PLAY [localhost] ********************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 

I am confused and this looks prety trivial thing but not sur to me what i am missing?

Thanks for help.

-VM

```

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 2, 2017, 9:19am UTC](https://forum.ansible.com/t/ansible-creating-a-file-on-local-machine-fails/25161/2 "2017-08-02T09:19:35Z")

</div>

> [localhost]  
> 127.0.0.1 ansible\_connection=local ansible\_ssh\_user=XXXX ansible\_ssh\_pass=XXXXXX
> 
> ansible\_ssh\_user is my ubuntu machine user( Question: Do I necessarily need to give the user and password here?)

This is not correct, localhost is not a group.  
Default Ansible sets "localhost ansible\_connection=local" so you do not need this set in your inventory.

Since ansible\_connection=local and not ssh you don't need to set ansible\_ssh\_user/pass since it will not be using ssh, it will run the command directly on the localhost in the current shell.

> And since it shows permission issue, I include become: yes in the role as below
> 
> - hosts: localhost  
> &nbsp;&nbsp;&nbsp;become: yes  
> &nbsp;&nbsp;&nbsp;roles:  
> &nbsp;&nbsp;&nbsp;&nbsp;- Local\_File
> 
> then i get the following error:  
> vmisra@ubuntu:/etc/ansible$ ansible-playbook vcenter\_snaprestore.yml  
> [WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting
> 
> PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [127.0.0.1]: FAILED! =\> {"changed": false, "failed": true, "module\_stderr": "sudo: a password is required\n", "module\_stdout": "", "msg": "MODULE FAILURE", "rc":
> 
> I am confused and this looks prety trivial thing but not sur to me what i am missing?

As the error message say "sudo: a password is required", since you can't run sudo without specifying a password you need to provide the sudo password to Ansible.

To do that add -K or --ask-become-pass on the command line

ansible-playbook -K vcenter\_snaprestore.yml
