fail to exec apt-get upgrade (change from notrun to 0 failed...)

4,510 views
Skip to first unread message

Stoyan Nikolov

unread,
Sep 14, 2011, 10:37:41 AM9/14/11
to puppet...@googlegroups.com
So here is my manifest:

class aguu {

        exec { "update":
                command => "apt-get update",
                path => "/usr/bin/"
        }

        exec { "upgrade":
                command => "apt-get upgrade -y",
                path => "/usr/bin/"
        }
}

It it supposed to run apt-get update + upgrade

This is the output I get:

info: Applying configuration version '1316008127'
notice: //aguu/Exec[update]/returns: executed successfully
err: //aguu/Exec[upgrade]/returns: change from notrun to 0 failed: apt-get upgrade -y returned 100 instead of one of [0] at /etc/puppet/modules/aguu/manifests/init.pp:11
notice: //testmodule1/File[/tmp/testmodule]/ensure: created
warning: Value of 'preferred_serialization_format' (pson) is invalid for report, using default (marshal)
notice: Finished catalog run in 3.60 seconds

Apt-get should be returning 100 in case of an error, but if i run the exact same command from command line it runs fine.
Any suggestions what should be going wrong?

Craig White

unread,
Sep 14, 2011, 11:58:55 AM9/14/11
to puppet...@googlegroups.com

----
It's entirely possible to have something blocking the run of 'apt-get -y upgrade' such as unresolved dependencies which may require you to execute 'apt-get -f install' in order to get something done.

Generally, you can check the result of a command by typing 'echo $?' to see the exit status... ie
apt-get upgrade -y; echo $?

as for your particular issue... hard to know for sure but it may be useful to see how I handle this. In a general explanation, I create a directory /etc/puppet/deployment_files and in that directory, I sometimes put things I need for deployment status or triggering.

This is what my 'apt updates' class looks like...

class apt::updates {
include mod_puppet::deployment_files
# Puppet maintained file /etc/puppet/deployment_files/apt_update_initiator
file { "/etc/puppet/deployment_files/apt_update_initiator":
source => "puppet://puppet/modules/apt/apt_update_initiator",
require => Class["mod_puppet::deployment_files"],
ensure => present,
owner => root,
group => root,
mode => 0644,
}
exec { "/usr/bin/aptitude update":
refreshonly => true,
subscribe => File["/etc/puppet/deployment_files/apt_update_initiator"],
}
# Puppet maintained file /etc/puppet/deployment_files/apt_safe_upgrade_initiator
file { "/etc/puppet/deployment_files//apt_safe_upgrade_initiator":
source => "puppet://puppet/modules/apt/apt_safe_upgrade_initiator",
require => [ Class["mod_puppet::deployment_files"], Exec["/usr/bin/aptitude update"] ],
ensure => present,
owner => root,
group => root,
mode => 0644,
}
exec { "/usr/bin/aptitude -y safe-upgrade":
refreshonly => true,
subscribe => File["/etc/puppet/deployment_files/apt_safe_upgrade_initiator"],
}
# Puppet maintained file /etc/puppet/deployment_files/apt_full_upgrade_initiator
file { "/etc/puppet/deployment_files/apt_full_upgrade_initiator":
source => "puppet://puppet/modules/apt/apt_full_upgrade_initiator",
require => [ Class["mod_puppet::deployment_files"], Exec["/usr/bin/aptitude update"] ],
ensure => present,
owner => root,
group => root,
mode => 0644,
}
exec { "/usr/bin/aptitude -y full-upgrade":
refreshonly => true,
subscribe => File["/etc/puppet/deployment_files/apt_full_upgrade_initiator"],
}
}

and so I '/bin/date > /etc/puppet/modules/apt/files/apt_update_initiator' ( and also to apt_safe_upgrade_initiator and apt_full_upgrade_initiator ) and the first time this is deployed, all three files are copied and the commands are executed on each client. Note that 'Exec["/usr/bin/aptitude update"]' is required by the 'upgrades'

Then I have a cron run every night to put the date into the apt_update_initiator file on the puppet master so that forces each puppet client to execute and I can do the same to either of the 'upgrade' files to force them to upgrade.

On any client, I can check /etc/puppet/deployment_files/apt_[update|safe_upgrade|full_upgrade]_initiator to see the date and time I last instructed it to update/upgrade.

Craig

Stoyan Nikolov

unread,
Sep 14, 2011, 12:16:55 PM9/14/11
to puppet...@googlegroups.com
There isn't a problem with the "apt-get upgrade -y" command, because as i wrote in the original post, If i run that exact same command on the machine it works just fine. 

Here's the output of the "apt-get upgrade -y; echo $?"

root@agent3:~# apt-get upgrade -y; echo $?
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  ca-certificates capplets-data checkbox checkbox-gtk dbus dbus-x11
  dhcp3-client dhcp3-common firefox firefox-branding firefox-gnome-support
  foomatic-filters gnome-control-center libdbus-1-3 libgnome-window-settings1
  libgtk-vnc-1.0-0 libnss3-1d libpng12-0 librsvg2-2 librsvg2-common
  libsmbclient libsndfile1 libsoup-gnome2.4-1 libsoup2.4-1 libwbclient0
  libwebkit-1.0-2 libwebkit-1.0-common libxfont1 linux-headers-2.6.32-33
  linux-headers-2.6.32-33-generic linux-image-2.6.32-33-generic linux-libc-dev
  samba-common samba-common-bin smbclient xulrunner-1.9.2
36 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/92.7MB of archives.
After this operation, 45.1kB of additional disk space will be used.
Extracting templates from packages: 100%
Preconfiguring packages ...

--output omitted--

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
0


The 0 in the end is the apt-get return, and it means that there were no errors.

But if i run the exact same command through puppet it returns "100" which is apt-get's error code

Sergey Zhuga

unread,
Sep 14, 2011, 12:21:34 PM9/14/11
to puppet...@googlegroups.com
14.09.2011 17:37, Stoyan Nikolov пишет:

Do you use unsigned repositories?

Stoyan Nikolov

unread,
Sep 14, 2011, 12:28:17 PM9/14/11
to puppet...@googlegroups.com
No, i do not.

Martin Alfke

unread,
Sep 14, 2011, 12:31:37 PM9/14/11
to puppet...@googlegroups.com
On 14.09.2011, at 18:16, Stoyan Nikolov wrote:

There isn't a problem with the "apt-get upgrade -y" command, because as i wrote in the original post, If i run that exact same command on the machine it works just fine. 

Here's the output of the "apt-get upgrade -y; echo $?"

root@agent3:~# apt-get upgrade -y; echo $?
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  ca-certificates capplets-data checkbox checkbox-gtk dbus dbus-x11
  dhcp3-client dhcp3-common firefox firefox-branding firefox-gnome-support
  foomatic-filters gnome-control-center libdbus-1-3 libgnome-window-settings1
  libgtk-vnc-1.0-0 libnss3-1d libpng12-0 librsvg2-2 librsvg2-common
  libsmbclient libsndfile1 libsoup-gnome2.4-1 libsoup2.4-1 libwbclient0
  libwebkit-1.0-2 libwebkit-1.0-common libxfont1 linux-headers-2.6.32-33
  linux-headers-2.6.32-33-generic linux-image-2.6.32-33-generic linux-libc-dev
  samba-common samba-common-bin smbclient xulrunner-1.9.2
36 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/92.7MB of archives.
After this operation, 45.1kB of additional disk space will be used.
Extracting templates from packages: 100%
Preconfiguring packages …

Does any of these packages require user interaction via debconf?


--output omitted--

Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
0


The 0 in the end is the apt-get return, and it means that there were no errors.

But if i run the exact same command through puppet it returns "100" which is apt-get's error code

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/efCy34kA-m8J.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Stoyan Nikolov

unread,
Sep 14, 2011, 12:46:12 PM9/14/11
to puppet...@googlegroups.com
Not.

My linux knowledge is very limited, so these are clean ubuntu installations that i set up so i can test puppet.


Message has been deleted

Stoyan Nikolov

unread,
Sep 14, 2011, 12:54:47 PM9/14/11
to puppet...@googlegroups.com
I have to add, if i run "apt-get upgrade -y"  manually on a machine, and then run the manifest again it works fine: 

(after running "apt-get upgrade -y" manually)

root@agent3:~# puppetd --test
info: Caching catalog for agent3.sabrewolf.net
info: Applying configuration version '1316008127'
notice: //aguu/Exec[upgrade]/returns: executed successfully
notice: //aguu/Exec[update]/returns: executed successfully
warning: Value of 'preferred_serialization_format' (pson) is invalid for report, using default (marshal)
notice: Finished catalog run in 34.87 seconds

But I suspect that as soon as it will actually need to upgrade the repositories it will fail again...

Craig White

unread,
Sep 14, 2011, 1:07:54 PM9/14/11
to puppet...@googlegroups.com

----
I do too but the problem isn't puppet... the problem is what happens from the command line executions of apt-get/aptitude/etc. which obviously leave apt in a state where it requires console interaction to resolve. If you stop using apt from command line, you won't have a problem with the puppet commands. If you use apt on the command line, you should learn to clean up after yourself and run things like 'apt-get -f install' (to install needed dependencies), 'apt-get autoremove' (to clean up unneeded packages), etc.

Also note that the package cache will get stale over time and you would need to run 'apt-get update' prior to running 'apt-get update -y' which is why I told you to note how I used 'require' in my puppet manifests to ensure that happens first.

Craig

Stoyan Nikolov

unread,
Sep 14, 2011, 2:53:46 PM9/14/11
to puppet...@googlegroups.com
Solved my problem:

Defined global paths for execs including the common locations for executables:

Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }

Previously i had just /usr/bin/ where apt-get is located.
Apparently apt-get runs scripts that require executables that cannot be found in that directory which resulted in an error.
Things are running as expected now.
Reply all
Reply to author
Forward
0 new messages