diff --git a/README.md b/README.md index 4458f2c..77b5086 100644 --- a/README.md +++ b/README.md @@ -162,5 +162,179 @@ Congratulations! Your Puppet Master and Puppet Agent are now set up and running. ![chef-vs-puppet-vs-ansible-what-are-the-differences-it-infographic](https://github.com/vishal815/Puppet_Master_and_Puppet_slave_setup_on_AWS/assets/83393190/f3cf14d2-e39e-49ad-b514-634a8b475099) -Happy learning! +# script and instructions for setting up a Puppet manifest on the Master node and applying it on the Slave node. Here's a cleaned-up version of your instructions: + +### Master Node: + +1. **Navigate to the Puppet directory:** + ```bash + cd /etc/puppetlabs + ``` + +2. **List the contents:** + ```bash + ls + ``` + +3. **Navigate to the code directory:** + ```bash + cd code + ``` + +4. **List the contents:** + ```bash + ls + ``` + +5. **Create the necessary directories:** + ```bash + sudo mkdir -p environments/production/manifests/ + ``` + +6. **Navigate to the manifests directory:** + ```bash + cd environments/production/manifests/ + ``` + +7. **Create a new manifest file (`site.pp`):** + ```bash + sudo nano site.pp + ``` + +8. **Add the following content to the `site.pp` file:** + ```puppet + node default { + # 1st resource: Install Nginx + package { 'nginx': + ensure => installed, + } + + # 2nd resource: Create a status file + file { '/tmp/status.txt': + content => 'Nginx has been installed successfully', + mode => '0644', + } + } + ``` + +9. **Save and exit the editor:** + - Press `Ctrl + X` to exit. + - Press `Y` to confirm saving. + - Press `Enter` to save the file with the same name. + +### Slave Node: + +1. **Apply the Puppet catalog:** + ```bash + sudo /opt/puppetlabs/bin/puppet agent --test + ``` + +2. **Verify Nginx installation:** + - Copy the public IP of the slave node. + - Open a web browser and paste the IP. + - Hit `Enter` to check if it shows the Nginx default page. + +3. **Check the content of the status file:** + ```bash + cat /tmp/status.txt + ``` + - It should display: `Nginx has been installed successfully`. + +This should guide you through setting up your Puppet manifest and verifying its application on the slave node. + +# an example of a simple Puppet module that manages the installation and configuration of the Apache web server on a Linux system. + +### On the Puppet Master Server + +1. **Create the Module Directory Structure**: + ```bash + sudo mkdir -p /etc/puppetlabs/code/environments/production/modules/apache_example/{manifests,templates} + ``` + +2. **Create the `init.pp` Manifest**: + ```bash + sudo nano /etc/puppetlabs/code/environments/production/modules/apache_example/manifests/init.pp + ``` + + Add the following content: + ```puppet + class apache_example { + package { 'apache2': + ensure => 'installed', + } + + service { 'apache2': + ensure => 'running', + enable => true, + require => Package['apache2'], + } + + file { '/var/www/html/index.html': + ensure => 'file', + content => template('apache_example/index.html.erb'), + require => Package['apache2'], + } + } + ``` + +3. **Create the `index.html.erb` Template**: + ```bash + sudo nano /etc/puppetlabs/code/environments/production/modules/apache_example/templates/index.html.erb + ``` + + Add the following content: + ```html + + + Welcome to Apache on <%= @hostname %> + + +

Hello from Puppet-managed Apache on <%= @hostname %>!

+ + + ``` + +4. **Edit the Site Manifest (`site.pp`)**: + ```bash + sudo nano /etc/puppetlabs/code/environments/production/manifests/site.pp + ``` + + Add the following node definition: + ```puppet + node 'your_slave_node_fqdn' { + include apache_example + } + ``` + + Replace `your_slave_node_fqdn` with the actual FQDN of your Puppet Agent (Slave) node. + +### On the Puppet Agent (Slave) Server + +1. **Run Puppet Agent to Apply Configuration**: + After making changes on the Puppet Master, SSH into the Puppet Agent (Slave) node and run: + + ```bash + sudo /opt/puppetlabs/bin/puppet agent --test + ``` + + This command will: + - Connect the agent to the Puppet Master. + - Fetch the catalog that includes the `apache_example` module. + - Apply the configuration, which includes installing Apache, starting the Apache service, and creating a custom `index.html` file. + +### Verification + +1. **Check the Apache Service**: + Ensure that Apache is running on the Puppet Agent node: + + ```bash + sudo systemctl status apache2 + ``` + +2. **Verify the Web Page**: + Open a web browser and navigate to the IP address or domain of the Puppet Agent node (e.g., `http://`). You should see the custom welcome page with the message "Hello from Puppet-managed Apache on [hostname]!". + + + +