0

For example lets attempt to let Puppet install the opengeo-suite.

To do something like

wget -qO- http://apt.opengeo.org/gpg.key | apt-key add -
echo "deb http://apt.opengeo.org/suite/v3/ubuntu lucid main" >> /etc/apt/sources.list

we can use

exec {'getKey':
    command => "wget -qO- http://apt.opengeo.org/gpg.key | apt-key add -",
}

exec {'addRepo':
    command => "echo "deb http://apt.opengeo.org/suite/v3/ubuntu lucid main" >> /etc/apt/sources.list",
}

Question #1: If we run the puppet script again, won't the wget and echo be run twice? We will end up with duplicate repo in /etc/apt/sources.d. Running package { "opengeo-suite": } twice doesn't attempt to install the package twice, it simply ensures that its installed.

Question #2: Doing apt-get install opengeo-suite there are several promopts for user input. Will Puppet somehow know the default input to use, or will it crash?

Nyxynyx
  • 1,459
  • 11
  • 39
  • 49
  • 1
    Not to contradict any existing answers, but to add: `apt` also uses the directory `/etc/apt/sources.list.d` for repositories. Each file can contain one or more entries, and you can manage each file via Puppet `file` resources. *Much* easier than trying to work up idempotency via `grep` or other tools. – Mike Renfro Apr 21 '13 at 13:09

2 Answers2

3
  1. If you don't prevent it, the commands will be run at every puppet run, including multiple entries in the sources.list. This should not happen, as Puppet expects that exec calls are idempotent. One way around this is to to create "check" files and run the exec only if the check file is not present. See the doc to learn how to do this. Also note that there exist user-contributed modules to maintain apt repos with Puppet.

  2. I haven't used Puppet on an apt-based system (yet), but I guess that Puppet or the apt module I linked above is clever enough to handle this. If not, see this.

Sven
  • 98,649
  • 14
  • 180
  • 226
2

You can use onlyif into exec. The test has to return true in order to execute the command, in your case see bellow (the PUBLIC_KEY_ID it is the key id of the apt provider)

exec {'getKey':
  command => "wget -qO- http://apt.opengeo.org/gpg.key | apt-key add -",
  onlyif  => "test `apt-key list |grep PUBLIC_KEY_ID | wc -l ` -eq 0"
}

exec {'addRepo':
  command => "echo "deb http://apt.opengeo.org/suite/v3/ubuntu lucid main" /etc/apt/sources.list",
  onlyif  => "test `grep http://apt.opengeo.org/suite/v3/ubuntu /etc/apt/sources.list | wc -l ` -eq 0"
}
silviud
  • 2,687
  • 2
  • 18
  • 19