# upgrading apt packages, getting stderr: /bin/sh: apt-get: command not found

**URL:** <https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109>\
**Category:** Ansible Project\
**Created:** [April 29, 2014, 3:11am UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109 "2014-04-29T03:11:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gallagher\_Polyn](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gallagher\_Polyn](https://forum.ansible.com/u/Gallagher_Polyn)\
**Post date:** [April 29, 2014, 3:11am UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109/1 "2014-04-29T03:11:01Z")

</div>

Hi,

Having just provisioned a Digital Ocean droplet, in my next pre\_task, I proceed to attempt to upgrade apt packages:

> apt: upgrade=full update\_cache=yes

…using this command form…

> ansible-playbook -i hosts basic.yml -vvvv

…I obtain the following error:

> failed: [127.0.0.1] =\> {“cmd”: “apt-get update && apt-get install python-apt -y -q”, “failed”: true, “rc”: 127}  
> stderr: /bin/sh: apt-get: command not found  
> msg: /bin/sh: apt-get: command not found

Shelling into the newly-provisioned droplet as root, however, I am able to execute apt-get update normally.

Any thoughts?

Thanks,

Gallagher

---

<div class="post-metadata">

**Author:** ![Ralph](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ralph](https://forum.ansible.com/u/Ralph)\
**Post date:** [April 29, 2014, 7:15am UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109/2 "2014-04-29T07:15:43Z")

</div>

Hi,

my two cents would be:

1. Make sure you use absolute paths when invoking the “apt-get update” and “apt-get install” commands (_whereis apt-get_ helps here…)
2. Make sure you use the “shell” module instead of the “command” module since the shell module allows redirection and pipe and that kind of stuff  
Cheers  
Ralph

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 29, 2014, 12:37pm UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109/3 "2014-04-29T12:37:16Z")

</div>

Hi Ralph,

He’s using the apt module not shelling out to apt directly.

The basic initial questions are “what versions of Ansible are you using” and “what is the OS version you are using”.

We can go from there.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ralph](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Ralph](https://forum.ansible.com/u/Ralph)\
**Post date:** [April 29, 2014, 12:52pm UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109/4 "2014-04-29T12:52:00Z")

</div>

…ahh sorry, my mistake. My eyes sort of went straight to the error. I should’ve grabbed a coffee before answering…

---

<div class="post-metadata">

**Author:** ![Gallagher\_Polyn](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gallagher\_Polyn](https://forum.ansible.com/u/Gallagher_Polyn)\
**Post date:** [April 29, 2014, 3:56pm UTC](https://forum.ansible.com/t/upgrading-apt-packages-getting-stderr-bin-sh-apt-get-command-not-found/15109/5 "2014-04-29T15:56:39Z")

</div>

> > > > …I obtain the following error:
> > > > 
> > > > > failed: [127.0.0.1] =\> {“cmd”: “apt-get update && apt-get install python-apt -y -q”, “failed”: true, “rc”: 127}  
> > > > > stderr: /bin/sh: apt-get: command not found  
> > > > > msg: /bin/sh: apt-get: command not found

Resolution: I had failed to use the add\_host module and the command was failing because it was being run on the wrong machine, namely, localhost.

Hopeful Request: Can someone please point to an example of Digital Ocean provisioning plus configuration with Ansible? (I’ve seen examples of one or the other, not both.)

Thanks,

G
