Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run `apt-get update` before installing other packages with Puppet

I'm trying to create puppet module which automates installation of zend server CE, this is not important here, but steps are as following

  1. update /etc/apt/source.list
  2. download repos key via wget
  3. do apt-get update
  4. do apt-get install zend-server-ce-5.2

I have init.pp file

class zendserverce {  # https://github.com/puppetlabs/puppetlabs-stdlib file_line { 'debian_package':     path => '/etc/apt/sources.list',     line => 'deb http://repos.zend.com/zend-server/deb server non-free' }  exec { "wget http://repos.zend.com/zend.key -O- |apt-key add -":     path => ["/usr/bin", "/usr/sbin"] }  exec { "apt-get update":     command => "/usr/bin/apt-get update",     onlyif  => "/bin/sh -c '[ ! -f /var/cache/apt/pkgcache.bin ] || /usr/bin/find /etc/apt/* -cnewer /var/cache/apt/pkgcache.bin | /bin/grep . > /dev/null'", }  package { "zend-server-ce-php-5.2":     ensure => "latest" }  } 

Seems that puppet runs commands in different order then I need. Is there any way how to for tell him to run in my desired order?

The output of such snippet is

  [0;36mnotice: /Stage[main]/Mc/Package[mc]/ensure: ensure changed 'purged' to 'latest'[0m   [1;35merr: /Stage[main]/Zendserverce/Package[zend-server-ce-php-5.2]/ensure: change from purged to latest failed: Could not update: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install zend-server-ce-php-5.2' returned 100: Reading package lists...   Building dependency tree...   Reading state information...   E: Couldn't find package zend-server-ce-php-5.2 at /tmp/vagrant-puppet/modules 0/zendserverce/manifests/init.pp:28[0m   [0;36mnotice: /Stage[main]/Zendserverce/Exec[wget http://repos.zend.com/zend.key -O- |apt-key add -]/returns: executed successfully[0m   [0;36mnotice: /Stage[main]/Zendserverce/File_line[debian_package]/ensure: created[0m   [0;36mnotice: Finished catalog run in 6.75 seconds[0m 

So it says: Couldn't find package zend-server-ce-php-5.2

Can anyone guide me what is wrong?

like image 595
Jaro Avatar asked Jun 01 '12 07:06

Jaro


People also ask

Does apt update install packages?

APT is an Advanced packaging Tool that performs various tasks: new software packages installation, upgrades the existing installed packages, updates the packages index list, and you can also even upgrade the Ubuntu or Debian system using the apt command.

How do I force upgrade apt-get?

Copy and paste sudo dpkg --configure -a into the Terminal. You can also try: sudo apt-get install -f to fix broken dependencies.

What does APT update && apt upgrade do?

The sudo apt-get upgrade command downloads and installs the updates for each outdated package and dependency on your system. But just running sudo apt-get upgrade will not automatically upgrade the outdated packages – you'll still have a chance to review the changes and confirm that you want to perform the upgrades.


2 Answers

Since Puppet 2.6.0 a new feature "relationship syntax" was introduced.

An example in Puppet 2.6.0 and above would look like this:

exec { "apt-update":     command => "/usr/bin/apt-get update" }  Exec["apt-update"] -> Package <| |> 

Every time a package command is executed, the dependency (in our case 'apt-update') will be triggered fist. You can even define longer chains.

like image 160
DrDol Avatar answered Sep 25 '22 15:09

DrDol


You need to specify the dependency relationships. The easiest/cleanest approach is to use the require parameter which is available for all resource types.

package { "zend-server-ce-php-5.2":   ensure  => latest,   require  => Exec['apt-get update'], } 

etc..

like image 45
czervik Avatar answered Sep 24 '22 15:09

czervik