Linux
Linux
[Date]
[nom de la société]
Introduction :
Puppet provides various resource types that you can manage to configure and
maintain systems. Each resource type represents a specific aspect of the
system's configuration. Here's a description of some common resource types in
Puppet and the operations you can apply to them:
1. **File Resource (`file`)**:
- Description: Manages files and directories on the system.
- Operations: Create, delete, ensure existence, set permissions, manage
content, and create symbolic links.
2. **Package Resource (`package`)**:
- Description: Manages software packages on the system.
- Operations: Install, uninstall, ensure version, upgrade, and pin to specific
versions.
3. **Service Resource (`service`)**:
- Description: Manages system services (e.g., daemons).
- Operations: Start, stop, restart, enable, disable, and ensure the service is
running.
4. **User Resource (`user`)**:
- Description: Manages user accounts.
- Operations: Create, delete, set passwords, manage home directories, and
manage user groups.
5. **Group Resource (`group`)**:
- Description: Manages user groups.
- Operations: Create, delete, manage group members.
6. **Exec Resource (`exec`)**:
- Description: Runs arbitrary commands or scripts.
- Operations: Execute commands, scripts, and specify conditions for
execution.
7. **Package Repo Resource (`yumrepo` or `aptrepo`)**:
- Description: Manages package repositories.
- Operations: Add, remove, enable, disable repositories.
8. **Cron Resource (`cron`)**:
- Description: Manages cron jobs (scheduled tasks).
- Operations: Create, delete, and manage cron jobs.
9. **Host Resource (`host`)**:
- Description: Manages entries in the system's host file.
- Operations: Add, delete, and modify host entries.
10. **Firewall Resource (`firewall`)**:
- Description: Manages firewall rules.
- Operations: Create, delete, and modify firewall rules.
11. **Custom Types and Providers**:
- Description: Puppet allows you to create custom resource types and
providers for managing specialized configurations. These can be highly
customized to your specific needs.
12. **Notify Resource (`notify`)**:
- Description: A debugging resource used for sending messages to the Puppet
log.
- Operations: Display messages in the log for debugging purposes.
13. **Augeas Resource (`augeas`)**:
- Description: Manages configuration files using the Augeas configuration
tool.
- Operations: Modify and validate configuration file entries.
14. **Mount Resource (`mount`)**:
- Description: Manages mounted file systems.
- Operations: Mount, unmount, and manage mounted file systems.
15. **Scheduled Task Resource (`scheduled_task`)** (Windows only):
- Description: Manages scheduled tasks on Windows systems.
- Operations: Create, delete, and manage scheduled tasks.
Solution :
Write a Puppet manifest that installs the MySQL server package, starts the
MySQL service, and sets the root password to "mysecretpassword".
Solution not complete:
solution:
The problem here is that the port 80 was already in used by the Apache2 server
so therefore the containers can’t us the same port this is why I changed the
port number from 80 to 81 :
#!/bin/bash
#!/bin/bash
# Ensure you are connected to the correct Kubernetes cluster and
namespace.
kubectl config use-context hacker-company
# Create the secret
kubectl create secret generic application \
--namespace hacker-company \
--from-literal=checksum="$application_checksum"
Part2:
create a new generic secret "deployment" with the key "ssh_key" and the value
from the host's ssh private key "/id_rsa.pub", in the "hacker-company"
namespace.
Solution:
#!/bin/bash
# Ensure you are connected to the correct Kubernetes cluster and
namespace.
kubectl config use-context hacker-company
# Read the SSH private key from the file
ssh_key_value=$(cat /id_rsa)
Or we can use :
# Create the secret
kubectl create secret generic deployment \
#!/bin/bash
# Ensure you are connected to the correct Kubernetes cluster and
namespace.
kubectl config use-context hacker-company
# Create the secret
kubectl create secret generic deployment \
--namespace hacker-company \
--from-file=ssh_key=/id_rsa.pub
#!/bin/bash
# Step 2: Deploy a new "redis" image from DockerHub on the "buster" tag as
"web-application" deployment
kubectl create deployment web-application --image=redis:buster --
namespace=hacker-company
or not sure :
#!/bin/bash
Terraform :Docker :
we need to deploy a web application using terraform . complete a fole stub
"/home/ubunto/docker/main.tf" using HCL with one or more steps that do the
following :
initialize the provider plugin "kreuzwerker/docker", at version "2.11.0"
using a "docker_container" resource, create a new docker container from an
"nginx" image on "latest" tag, with the container name "web" and a published
port " 80"
solution:
version 1:
# Initialize the Terraform configuration
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.11.0"
}
}
}
# Define the Docker image resource
resource "docker_image" "nginx" {
name = "nginx:latest"
}
# Define the Docker container resource
resource "docker_container" "web" {
image = docker_image.nginx.image_id
name = "web"
ports {
internal = 80 (required the port of the container)
external = 8080 (optional the port for your local machine)
# Initialize the Terraform configuration
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.11.0"
}
}
}
# Configure the Docker provider
provider "docker" {}
Initialize Terraform:
terraform init
Plan the Deployment
terraform plan
Apply the configuration:
terraform apply
remove settings: