Tag Archives: puppet

Puppet: apt-get update before Package installation

Obvious way:

1
2
3
4
package {
        'pssh': ensure => 'present',
         require  => Exec['apt-get update']
}

But if you have several package definitions with Exec in each of them — apt-get update will be executed several times.

I found a better way:

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

It'll execute apt-get update one time before Packages.

Puppet: ubuntu update

This puppet config will make apt-get update && apt-get upgrade once a day between 2 and 4 hours.
Put it in manifests/site.pp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Exec { path => '/usr/bin:/bin:/usr/sbin:/sbin' }

class update {
        schedule { 'maintenance':
                  range  => "2 - 4",
                  period => daily,
                  repeat => 1,
        }

        exec { "upgrade_packages":
                command => "apt-get upgrade -q=2 -y",
                group => "root",
                user => "root",
                schedule => 'maintenance',
                onlyif => ["apt-get update"]
        }
}

node default {
        include update
}

Puppet: add string to /etc/hosts

add to /etc/puppet/manifests/site.pp

1
2
3
4
5
6
7
8
9
10
11
class hosts {
  host { 'host1.local':
    ensure => 'present',
    target => '/etc/hosts',
    ip => '192.168.192.31'
  }
}

node default {
  include hosts
}

It'll add string:

192.168.192.31 host1.local to /etc/hosts

Puppet: install software

add to /etc/puppet/manifests/site.pp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class soft {
  package {
    "htop":
    ensure => "installed"
  }

  package {
    "iptraf":
    ensure => "installed"
  }
}

node default {
  include soft
}

It'll install htop and iptraf utilites to all clients.

puppet: step-by-step

Server:

apt-get install puppet puppetmaster
insert into /etc/puppet/manifests/site.pp

1
2
3
4
5
6
7
8
9
10
11
12
class common {
  file { "/tmp/testfile":
    owner => root,
    group => admin,
    mode => 664,
    ensure => present
  }
}

node default {
  include common
}

/etc/init.d/puppetmaster restart

Client:

apt-get install puppet

1
openssl s_client -connect 127.0.0.1:8140 |grep subject
1
2
...
subject=/CN=puppet-master.local

add to /etc/puppet/puppet.conf

1
server=puppet-master.local
1
puppetd --verbose --test

Server:

1
puppetca --sign --all

 

Client:

1
puppetd --verbose --test


/etc/init.d/puppet start