# Ansible writing to a file

**URL:** <https://forum.ansible.com/t/ansible-writing-to-a-file/34719>\
**Category:** Ansible Project\
**Created:** [March 3, 2021, 11:17pm UTC](https://forum.ansible.com/t/ansible-writing-to-a-file/34719 "2021-03-03T23:17:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [March 3, 2021, 11:17pm UTC](https://forum.ansible.com/t/ansible-writing-to-a-file/34719/1 "2021-03-03T23:17:35Z")

</div>

Hi all,

So I’m trying to write to a local file from my ansible server based off information I’ve gotten from my inventory hosts. For some reason, it keeps creating the file ON the inventory host instead of my ansible server. Here is my playbook:

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [March 4, 2021, 5:37am UTC](https://forum.ansible.com/t/ansible-writing-to-a-file/34719/2 "2021-03-04T05:37:44Z")

</div>

looks like you have missed " delegate\_to: localhost" in first task.

---

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [March 9, 2021, 11:28pm UTC](https://forum.ansible.com/t/ansible-writing-to-a-file/34719/3 "2021-03-09T23:28:09Z")

</div>

Thanks for the update, however, it looks like it’s not using the sudoer I’m wanting it to use. I have become: yes up top which I would think would run as the sudoer user I’m intending.

If I’m trying to run this playbook in my homedir which is where all my others are initiated from and added become: yes and knowing that the sudoer user is listed in my ansible.cfg file, it doesn’t seem to be running as that.

---

<div class="post-metadata">

**Author:** ![Somasundaram\_R](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Somasundaram\_R](https://forum.ansible.com/u/Somasundaram_R)\
**Post date:** [March 10, 2021, 4:36pm UTC](https://forum.ansible.com/t/ansible-writing-to-a-file/34719/4 "2021-03-10T16:36:51Z")

</div>

Have you included **become\_method: sudo**?
