Module 4: Puppet Assignment - 1

Tasks To Be Performed:

  1. Setup Puppet master-slave using 3 nodes
  2. Installing Apache on slaves using manifests

Step 1:

Installing Puppet


Step 2:

class apache {
  package {
    'httpd':
      ensure => installed,
      provider => (osfamily == 'RedHat' ? 'yum' : 'apt'),
  }
 
  service {
    'httpd':
      ensure => running,
      enable => true,
      name   => 'httpd',
  }
 
  file {
    '/var/www/html/index.html':
      ensure => present,
      content => template('apache/index.html.erb'),
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      notify => Service['httpd'],
  }
}

I think the path was alredy there

sudo mkdir -p /etc/puppetlabs/code/environments/production/manifests

path was already there, after install

ubuntu@ip-10-0-1-244:~$ sudo tree /etc/puppetlabs/code/
/etc/puppetlabs/code/
├── environments
   └── production
       ├── data
       ├── environment.conf
       ├── hiera.yaml
       ├── manifests
       └── modules
└── modules
 
6 directories, 2 files

Created site.pp inside manifests,

Needed to add hostnames in etc/hosts for the agents

What I have so far

ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$ tree
.
└── production
    ├── data
    ├── environment.conf
    ├── hiera.yaml
    ├── manifests
    │   └── site.pp
    └── modules
        └── apache
            ├── apache.pp
            └── templates
                └── index.html.erb
 
6 directories, 5 files
ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$ cat production/manifests/site.pp
node 'agent' {
  include apache
}
 
node 'agent2' {
  include apache
}
ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$ cat production/modules/apache/apache.pp
class apache {
  package {
    'httpd':
      ensure => installed,
      provider => (osfamily == 'RedHat' ? 'yum' : 'apt'),
  }
 
  service {
    'httpd':
      ensure => running,
      enable => true,
      name   => 'httpd',
  }
 
  file {
    '/var/www/html/index.html':
      ensure => present,
      content => template('apache/index.html.erb'),
      mode    => '0644',
      owner   => 'root',
      group   => 'root',
      notify => Service['httpd'],
  }
}
ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$ cat production/modules/apache/templates/index.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Welcome to Apache!</title>
</head>
<body>
  <h1>Welcome to Apache!</h1>
  <p>This is a simple default webpage from Puppet.</p>
</body>
</html>
 
 
ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$

I’ll add the agents in /etc/hosts

Issue

ubuntu@ip-10-0-1-7:~$ puppet agent --test
Info: Refreshed CRL: BC:58:63:59:1A:85:0D:DA:5C:0C:CF:B5:9E:70:29:8F:B8:10:A6:76:18:43:CC:0E:5E:61:39:FA:CF:16:AA:C7
Info: Creating a new RSA SSL key for ip-10-0-1-7.ec2.internal
Info: csr_attributes file loading from /home/ubuntu/.puppetlabs/etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for ip-10-0-1-7.ec2.internal
Info: Certificate Request fingerprint (SHA256): 88:DD:F2:75:33:D8:59:47:A8:3F:76:11:32:EC:D4:08:D5:1C:0C:F2:24:21:DA:A5:88:4D:2B:CF:EE:4A:9E:6D
Info: Downloaded certificate for ip-10-0-1-7.ec2.internal from https://puppet:8140/puppet-ca/v1
Error: The certificate for 'CN=ip-10-0-1-7.ec2.internal' does not match its private key
Error: The certificate for 'CN=ip-10-0-1-7.ec2.internal' does not match its private key
ubuntu@ip-10-0-1-7:~$


used sudo, got new error

correct command with sudo

sudo /opt/puppetlabs/puppet/bin/puppet agent --test
ubuntu@ip-10-0-1-112:~$ sudo /opt/puppetlabs/bin/puppet agent --test
Info: Refreshing CA certificate
Info: CA certificate is unmodified, using existing CA certificate
Info: Refreshing CRL
Info: CRL is unmodified, using existing CRL
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not find node statement with name 'default' or 'ip-10-0-1-112.ec2.internal' on node ip-10-0-1-112.ec2.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
ubuntu@ip-10-0-1-112:~$

the new error node looks for its confuration on the server based on its hostname which is given by aws ip-10-0-1-112.ec2.internal this hostname is pingable.

This is the fully qualified domain name of the agent node which we can find with hostname --fqdn

Now new error i think becaus of syntax

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::apache for ip-10-0-1-112.ec2.internal (file: /etc/puppetlabs/code/environments/production/manifests/site.pp, line: 6, column: 3) on node ip-10-0-1-112.ec2.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

this is due to the moduel structure

Had an error validating init.pp

sudo /opt/puppetlabs/bin/puppet parser validate /etc/puppetlabs/code/environments/production/modules/apache/manifests/init.pp

New error from stuff in init.pp

finally works



Lets try agent1

Spinning new agent1 to replace 10.0.1.7 just for testing, end 108 was able to duplicate the install

This what worked

Module structure

ubuntu@ip-10-0-1-249:/etc/puppetlabs/code/environments$ tree
.
└── production
    ├── data
    ├── environment.conf
    ├── hiera.yaml
    ├── manifests
    │   └── site.pp
    └── modules
        └── apache
            ├── manifests
            │   └── init.pp
            └── templates
                └── index.html.erb
 
7 directories, 5 files

change to

index.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Welcome to Apache!</title>
</head>
<body>
  <h1>Welcome to Apache!</h1>
  <p>This is a simple default webpage from Puppet.</p>
</body>
</html>