Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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 Answers 2

  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.

share|improve this answer

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"
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.