# The "fetch" command is not executed with root (via sudo) privileges?

**URL:** <https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217>\
**Category:** Ansible Project\
**Created:** [July 30, 2013, 7:52am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217 "2013-07-30T07:52:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [July 30, 2013, 7:52am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/1 "2013-07-30T07:52:20Z")

</div>

Hi List,

I’m trying to store certain private keys to a central repository after creating those users and keys.

I wanted to copy those key’s using the “fetch” module, but I’m starting to think the module is not executed via sudo?

This is the command:

> - name: DTR | Kopieer private SSH key  
> action: fetch  
> src=/home/${item.user}/.ssh/id\_rsa  
> dest=/media/storage/keys/dtr  
> with\_items: $dtr\_accounts

And I also tried:

> - name: DTR | Kopieer private SSH key  
> action: fetch  
> src=/home/${item.user}/.ssh/id\_rsa  
> dest=/media/storage/keys/dtr  
> sudo: yes  
> sudo\_user: root  
> with\_items: $dtr\_accounts

But it still fails with:

> fatal: [pdtrdalton] =\> failed to transfer file from /home/mqtshur/.ssh/id\_rsa  
> FATAL: all hosts have already failed – aborting

Is my thinking true? Fetch is run under your own account?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [July 30, 2013, 11:38am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/2 "2013-07-30T11:38:52Z")

</div>

Known issue, if you need to use sudo you must use as slurp. Fetch will be modified to do this, but doesn’t,t support it yet.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [July 30, 2013, 11:52am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/3 "2013-07-30T11:52:50Z")

</div>

> 

That is somewhat disappointing. Seeing as this used to work fine, and was only recently revisiting this playbook only to find it no longer worked. (After removing all the only\_if statements, which apparently also no longer work).

Ok, I will have to wait for it to happen then. Can I use our service-contract with ansibleworks to “vote” on issues or something like it? (That would be cool by the way)

Thanks!  
Mark

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [July 30, 2013, 12:31pm UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/4 "2013-07-30T12:31:03Z")

</div>

I don’t know if fetch ever worked, but only if still does in my plays.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 30, 2013, 1:32pm UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/5 "2013-07-30T13:32:02Z")

</div>

Hi Mark, fetch mode with sudo is a feature request we have open, but I’m also pretty sure it was never implemented. Given, my memory over the last 1.5 years of the thousands of commits is not always perfect! 🙂

As for support contract issues, you should have been given information on how to use that to open requests/tickets, let me know off list if you did not and I’ll get you hooked up.

–Michael

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [July 30, 2013, 9:21pm UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/6 "2013-07-30T21:21:36Z")

</div>

Used to work fine for me, pre-1.2. Doesn't anymore.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 30, 2013, 9:23pm UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/7 "2013-07-30T21:23:42Z")

</div>

Hmm, I think I remember now.

It always used to use slurp (which is wrong for large files), the fix uses “copy”, but should use slurp when permissions are denied.

For large files, slurp is bad because it pulls things into memory.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [August 28, 2013, 9:54am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/8 "2013-08-28T09:54:07Z")

</div>

Hi Michael,

any news on this? Or a work around? We are running Ansible 1.3, where it still seems to not work anymore.

Thanks!  
Mark

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [August 28, 2013, 10:12am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/9 "2013-08-28T10:12:46Z")

</div>

This is actually on my todo list for tomorrow, and will be included in the official 1.3 release. I’ll let you knitter when it’s ready for testing.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [September 2, 2013, 9:28am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/10 "2013-09-02T09:28:46Z")

</div>

Hi James!

I’ll donate a beer via Paypal if you fixed it 😜

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 2, 2013, 1:41pm UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/11 "2013-09-02T13:41:15Z")

</div>

This was fixed last Thursday, sorry for not updating this thread.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [September 5, 2013, 8:37am UTC](https://forum.ansible.com/t/the-fetch-command-is-not-executed-with-root-via-sudo-privileges/13217/12 "2013-09-05T08:37:56Z")

</div>

Fantastic! What’s the paypal address I can send the beer to?
