Tuesday 16 July 2024

How to Use Jenkinsfile to connect into Ansible Tower and execute a server reboot running a ansible playbook ?

Let’s create a Jenkinsfile that integrates with Ansible Tower and executes a playbook to reboot a server. We’ll also include parameters for environment, target hostname group, and boolean options.


First, make sure you have the following prerequisites:

  1. Jenkins: Set up Jenkins on your system.
  2. Ansible Tower: Ensure you have Ansible Tower installed and configured.
  3. SSH Key Pair: Set up an SSH key pair for authentication between Jenkins and Ansible Tower.

Now, let’s create the Jenkinsfile:

pipeline {
    agent any

    parameters {
        string(name: 'ENV', description: 'Environment (e.g., dev, staging, prod)')
        string(name: 'TARGET_HOSTNAME_GROUP', description: 'Ansible inventory group for target hosts')
        booleanParam(name: 'REBOOT_ENABLED', defaultValue: true, description: 'Enable server reboot')
    }

    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }

        stage('Run Ansible Playbook') {
            steps {
                script {
                    def ansiblePlaybookCmd = """
                        ansible-playbook -i ${TARGET_HOSTNAME_GROUP} playbook.yml
                        --extra-vars 'reboot_enabled=${REBOOT_ENABLED}'
                    """
                    sh ansiblePlaybookCmd
                }
            }
        }
    }
}

Explanation:

  • The Jenkinsfile defines a pipeline with two stages: “Checkout” and “Run Ansible Playbook.”
  • We use parameters to allow users to input the environment, target hostname group, and whether to enable server reboot.
  • In the “Run Ansible Playbook” stage, we execute the Ansible playbook using the provided parameters.
  • The ansible-playbook command includes the inventory group and an extra variable (reboot_enabled) to control the reboot behavior.


Make sure to adjust the playbook.yml path and customize the playbook according to your specific requirements. Additionally, ensure that Jenkins has the necessary permissions to execute Ansible playbooks on the target hosts.

Remember to replace placeholders (such as ${TARGET_HOSTNAME_GROUP}) with actual values in your environment. If you encounter any issues, feel free to ask for further assistance! 🚀


- For more information on integrating Ansible with Jenkins, you can explore the official Ansible Tower plugin for Jenkins1

- Additionally, check out the Red Hat blog post on integrating Ansible with Jenkins in a CI/CD process2..

####################################################################


Let’s enhance the Jenkinsfile by adding the three boolean parameters: rebootstop_application, and start_application. These parameters will allow you to control additional actions during your pipeline execution. Here’s the updated Jenkinsfile:


pipeline {
    agent any

    parameters {
        string(name: 'ENV', description: 'Environment (e.g., dev, staging, prod)')
        string(name: 'TARGET_HOSTNAME_GROUP', description: 'Ansible inventory group for target hosts')
        booleanParam(name: 'REBOOT_ENABLED', defaultValue: true, description: 'Enable server reboot')
        booleanParam(name: 'STOP_APP_ENABLED', defaultValue: false, description: 'Stop application before reboot')
        booleanParam(name: 'START_APP_ENABLED', defaultValue: false, description: 'Start application after reboot')
    }

    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }

        stage('Run Ansible Playbook') {
            steps {
                script {
                    def ansiblePlaybookCmd = """
                        ansible-playbook -i ${TARGET_HOSTNAME_GROUP} playbook.yml
                        --extra-vars 'reboot_enabled=${REBOOT_ENABLED}'
                        --extra-vars 'stop_app_enabled=${STOP_APP_ENABLED}'
                        --extra-vars 'start_app_enabled=${START_APP_ENABLED}'
                    """
                    sh ansiblePlaybookCmd
                }
            }
        }
    }
}

Explanation:

  • I’ve added three new boolean parameters: STOP_APP_ENABLED and START_APP_ENABLED.
  • If STOP_APP_ENABLED is set to true, the pipeline will stop the application before rebooting the server.
  • If START_APP_ENABLED is set to true, the pipeline will start the application after the server reboot.

Remember to adjust the playbook (playbook.yml) to handle these additional actions based on the provided parameters. Feel free to customize the playbook according to your specific requirements.

Tuesday 9 July 2024

How to Write a DevOps Handover Document

A DevOps Handover document template to help a person leaving a project pass on the work done to another engineer, so it is continued, the work is around the Ansible playbook, for ci/cd automation, Jenkins pipeline and GitLab repository..



                          ##### BEGINNING OF  DOCUMENT TEMPLATE #########

DevOps Handover Document

Project Overview

Provide a brief overview of the project, its objectives, and its key components.

  • Project Name:
  • Project Description:
  • Key Stakeholders:
  • Project Timeline:
  • Current Status:

Ansible Playbook

Overview

Provide an overview of the Ansible playbook used in the project.

  • Purpose: Describe the purpose of the playbook.
  • Main Playbooks and Roles: List the primary playbooks and roles, their locations, and their functions.
  • Dependencies: Outline any dependencies or prerequisites for running the playbooks.

Directory Structure

├── ansible/ │ ├── playbooks/ │ │ ├── main_playbook.yml │ │ └── other_playbooks.yml │ ├── roles/ │ │ ├── role1/ │ │ └── role2/ │ ├── inventory/ │ │ ├── production │ │ └── staging │ └── ansible.cfg
  • Playbooks: Detailed description of key playbooks and their functions.
  • Roles: Detailed description of key roles and their tasks.
  • Inventory: Description of the inventory files and their purpose.
  • Configuration: Any special configurations in ansible.cfg.

Running Playbooks

Provide step-by-step instructions for running the playbooks.

  1. Setup Environment:
    bash
    ansible-playbook -i inventory/production main_playbook.yml
  2. Common Commands:
    • Command for running a specific playbook.
    • Command for running playbooks in staging/production environments.
    • Command for checking the playbook syntax.
    • Any other relevant commands.

CI/CD Automation

Jenkins Pipeline

Overview

Provide an overview of the Jenkins pipeline configuration.

  • Purpose: Describe the pipeline’s role in the project.
  • Pipeline Stages: List and describe each stage of the pipeline.

Configuration

  • Jenkinsfile Location:
  • Pipeline Script: Provide a snippet or full script of the Jenkinsfile if possible.
  • Plugins: List the Jenkins plugins used and their purposes.

Common Tasks

  • Triggering Builds: How to manually trigger builds.
  • Monitoring Builds: How to monitor build status and logs.
  • Debugging Issues: Steps to debug common issues.

GitLab Repository

Overview

Provide an overview of the GitLab repository setup.

  • Repository URL:
  • Branches: List and describe the purpose of key branches (e.g., main, develop, feature/*, hotfix/*).
  • Branching Strategy: Explain the branching strategy used in the project.
  • Merge Requests: Outline the process for creating and reviewing merge requests.

Repository Structure

bash
├── .gitlab/ │ ├── ci/ │ │ ├── stages/ │ │ ├── jobs/ │ │ └── scripts/ ├── src/ │ ├── main/ │ └── test/ ├── docs/ └── README.md
  • Key Directories: Description of key directories and their contents.
  • CI Configuration: Details of GitLab CI configuration (.gitlab-ci.yml).

Common Tasks

  • Cloning the Repository:
    bash
    git clone <repository_url>
  • Working with Branches:
    • Creating a new branch.
    • Merging branches.
  • CI/CD Pipelines:
    • How to trigger pipelines.
    • Monitoring pipeline status.
    • Debugging failed pipelines.

Contacts and Resources

Provide a list of key contacts and resources for further assistance.

  • Project Manager: Name, email, phone number.
  • Technical Lead: Name, email, phone number.
  • Relevant Documentation: Links to any additional documentation or resources.
  • Access Credentials: Securely provide any necessary credentials or access details.

Additional Notes

Any additional notes, tips, or important information to be aware of.


Prepared by: [Your Name]
Date: [Date]


                                   ##### END OF  DOCUMENT TEMPLATE #########

Monday 8 July 2024

Kubernetes CKA Exam preparation Links

 Here is a link to of links for the material to help me prepare for the Kubernetes Administration Exam.








How to Prepare for Certified Kubernetes Administration (CKA) Exam - https://vmtechie.blog/2019/01/12/how-to-prepare-for-certified-kubernetes-administration-cka-exam/
PASSING CKA IS NOT HARD, BUT PREPARATION IS --- https://thecloudcaptain.com/blog/passing_cka_is_not_hard/
Studying for the Certified Kubernetes Administrator Exam - http://www.kubernet.io/

Saturday 6 July 2024

The Ultimate List of Python YouTube Channels – Real Python

 These are materials which can be used when learning to code in Python


The Ultimate List of Python YouTube Channels

Table of Contents


We couldn’t find a good, up-to-date list of Python developer or Python programming YouTube channels online.

Learning Python on YouTube is a viable option these days, and we’re excited about what this new medium can do for programming education.

There are some really good YouTube channels that focus on Python development out there, but we just couldn’t find a list that was both comprehensive and up-to-date. So we created our own with the best and most Pythonic YouTubers.

We initially wrote this list based on information we gathered by reading forum posts and searching YouTube for Python channels directly. We’ll continue to add to the list with your feedback. We plan to keep this list updated, so feel free to leave a comment at the end of the page or tweet at us if you think anything is missing or if you’d like to see your own YouTube Python tutorials added.

In order for a channel to be included in our list, it must:

  • Focus on Python tutorials
  • Not be brand-new (> 2,000 subscribers)
  • Be active (new videos are coming out) OR have an interesting archive with old content worth watching
Enjoy the Python goodness!

Al Sweigart

“Tons of sweet computer related tutorials and some other awesome videos too!”

Anaconda Inc.

“With over 4.5 million users, Anaconda is the world’s most popular Python data science platform. Anaconda, Inc. continues to lead open source projects like Anaconda, NumPy and SciPy that form the foundation of modern data science. Anaconda’s flagship product, Anaconda Enterprise, allows organizations to secure, govern, scale and extend Anaconda to deliver actionable insights that drive businesses and industries forward.”
In addition to their company developed videos, including a fun lego-mation and Pyception short, Anaconda’s YouTube channel contains all the videos from AnacondaCon, a gathering of the passionate community of data scientists, IT professionals, analysts, developers, and business leaders all using the Anaconda distribution.

Christian Thompson

“A little bit about me and a lot about Python programming for beginners. I am a middle and high school teacher who uses Python as my teaching language. I firmly believe anyone can (and should) learn to program a computer and that Python is the perfect language for doing so.”

Clever Programmer

“You can find awesome programming lessons here! Also, expect programming tips and tricks that will take your coding skills to the next level.”

CodingEntrepreneurs

“Coding for Entrepreneurs is a Programming Series for Non-Technical Founders. Learn Django, Python, APIs, Accepting Payments, Stripe, jQuery, Twitter Bootstrap, and much more.”

Corey Schafer

“This channel is focused on creating tutorials and walkthroughs for software developers, programmers, and engineers. We cover topics for all different skill levels, so whether you are a beginner or have many years of experience, this channel will have something for you.”

Chris Hawkes

“We’re going to learn about programming, web design, responsive web design, Reactjs, Django, Python, web scraping, games, forms applications and more!”

CS Dojo

“Hey everyone! My name is YK, and I make videos mostly about programming and computer science here.”

Data School (Kevin Markham)

“You’re trying to launch your career in data science, and I want to help you reach that goal! My in-depth tutorials will help you to master crucial data science topics using open source tools like Python and R.”

David Beazley

“An archive of David Beazley’s conference, user group, and training talks.”

Enthought

“For more than 15 years, Enthought has built AI solutions with science and engineering at the core. We accelerate digital transformation by enabling companies and their people to leverage the benefits of Artificial Intelligence and Machine Learning.”
Additionally, Enthought is best known for the early development, maintenance, and continued support of SciPy, as well as the primary sponsor for the SciPy US and EuroSciPy Conferences. In addition to the company developed content, this channel provides all the video recordings from the SciPy US and EuroScipy (before 2016) Conferences, talks and tutorials specifically focused on the advancement of scientific computing through open source Python software for mathematics, science, and engineering.

Michael Kennedy (Talk Python)

“Videos, demos, and lectures about programming - especially Python and web topics.”

PrettyPrinted

“I’m Anthony. I make programming videos.”

PyCon Session Recordings

These are all PyCon talk and session recordings made available on YouTube. There’s no single channel that combines these. Instead, you’ll access each year’s videos on a separate “PyCon 20…” channel. Alternatively, you can use PyVideo.org to watch the session recordings.

PyData

“PyData provides a forum for the international community of users and developers of data analysis tools to share ideas and learn from each other. The global PyData network promotes discussion of best practices, new approaches, and emerging technologies for data management, processing, analytics, and visualization. PyData communities approach data science using many languages, including (but not limited to) Python, Julia, and R.”

Real Python

“Python tutorials and training videos for Pythonistas that go beyond the basics. On this channel you’ll get new Python videos and screencasts every week. They’re bite-sized and to the point so you can fit them in with your day and pick up new Python skills on the side.”

Reuven Lerner

“I’m Reuven Lerner, and I teach Python and data science to companies around the world. On this YouTube channel, I publish videos that will help you with Python programming.”

Sentdex (Harrison Kinsley)

“Python Programming tutorials, going further than just the basics. Learn about machine learning, finance, data analysis, robotics, web development, game development and more.”

Socratica

“Socratica makes high-quality educational videos on math and science. New videos every week! We’re a couple of Caltech grads who believe you deserve better videos. You’ll learn more with us!”

TheNewBoston (Bucky Roberts)

“Tons of sweet computer related tutorials and some other awesome videos too!”

Smaller Python Conferences

The following channels provide the tutorials, talks, and session recordings from many of the smaller local Python conferences held throughout the world.

Though on their own, most of these channels do not meet the requirement for 2000 subscribers, we list them here as honorable mentions because they represent the diverse Python community throughout the world.

Note that some (maybe older) videos from these conferences are available (together with other non-Python content) on the Next Day Video and Engineers.SG channels. Alternatively, PyVideo.org can serve as a one-stop-shop where you can find most (but not all) of these session recordings.

If you think anything is missing from this list or if you’d like to see your own Python YouTube channel added, then please leave a comment below 

Thursday 4 July 2024

Azure tutorials with Terraform and Packer and Ansible ..

 Here are some links to be used to build and deploy Packer Image Automated Build, Provisioned with Ansible and Deployed into infrastructure with Terraform. 


Links list; 

- Microsoft Tutorial to Implement as tutorial and publish as Video Tutorial - https://cloudblogs.microsoft.com/opensource/2018/05/23/immutable-infrastructure-azure-vsts-terraform-packer-ansible/  ( This article my have few bugs and incompatibilities as it was done ages ago and the application has since moved into more advanced versions ) 


- Here - Creating VM Images with Packer in Microsoft Azure - https://medium.com/slalom-build/azure-packer-592c4dc0e23a  

- This tutorial is more oriented for Amazon AWS  instead of Azure - https://devopscube.com/packer-tutorial-for-beginners/   

- This another tutorial buils Terraform and Packer image build automation for Amazon AWS - https://www.bogotobogo.com/DevOps/Terraform/Terraform-state-tfstate-import.php  





4 – Videos to be implemented on Jobudo DevTeam Channel – Or create another Playlist on my existent TDLM Channel ..


I was glad to help! If you still have any questions, then be sure to contact us.
✅ Be sure to subscribe to our official social network:

Tuesday 2 July 2024

How to LVM resize filesystem Guide

 Increase the size of an LVM logical volume - Step-by-step Guide.

Tested on

Debian (Etch, Lenny, Squeeze)
Fedora (14)
Ubuntu (Hardy, Intrepid, Jaunty, Karmic, Lucid, Maverick, Natty)

Objective

To increase the size of an existing LVM logical volume

Background

Be aware that extending a logical volume does not by itself let you to store more files in a filesystem located on that volume. If that is your aim then you will need to:
  1. increase the size of the underlying block device (the logical volume), then
  2. increase the size of the filesystem to fill the block device.
These instructions cover the first step only. The method for the second step will depend on the type of filesystem (and in some cases there will be no practicable method). See below for further information.

Scenario

Suppose that /dev/vg0/foo is a logical volume of size 80GB. You wish to increase its size by 40GB to 120GB.

Method

A logical volume can be extended using the lvextend command. You can specify either the amount by which you want to increase the size of the volume:
lvextend --size +40G /dev/vg0/foo

or the final size that you want to achieve:
lvextend --size 120G /dev/vg0/foo

If successful you should see a response of the form:
Extending logical volume foo to 8.00 GB
Logical volume foo successfully resized

Testing

Verify the new size of the logical volume using the lvdisplay command:
lvdisplay /dev/vg0/foo

This should give a response of the form:
--- Logical volume ---
LV Name /dev/vg0/foo
VG Name vg0
LV UUID w2q9ZN-hKnN-CLGf-6Z5g-e1QZ-DCKX-1DYZvR
LV Write Access read/write
LV Status available
# open 0
LV Size 120.00 GB
Current LE 30720
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:85

You should not at this stage expect to see any increase in the amount of usable space within whatever filesystem located on the logical volume, for example, as reported by the df command: it is only the size of the underlying block device that has been changed.

Next steps

If the logical volume contains a filesystem then you will probably now want to extend it to fill the newly available space. Filesystems that can be extended include ext2, ext3, ext4, jfs, reiserfs and xfs. See:
Some filesystems cannot be extended, either because their design makes this impracticable or because the necessary software has not been written. In that case your only option is to move the files somewhere else, then recreate the filesystem, then move the files back.

Troubleshooting

Alternatives

lvresize

An alternative to lvextend is to use the lvresize command:
lvresize --size +40G /dev/vg0/foo

or:
lvresize --size 120G /dev/vg0/foo

The difference is that lvextend can only increase the size of a volume, whereas lvresize can increase or reduce it. This makes lvresize more powerful but more dangerous. If you accidentally reduce the size of a volume without first reducing the size of the filesystem contained within it then the filesystem is likely to be damaged irreparably. For scenarios similar to the one described here, lvextend is recommended because mistakes of this type are not then possible.

See also

Monday 1 July 2024

How to Reboot RedHat Server 9 using Jenkins and Ansible Playbooks

 In order for you to automate the process of Reboot RedHat Servers with Jenkins and Ansible Playbooks.

You have to create a Jenkins pipeline for an application that involves the following steps: rebooting a Red Hat Server 9 using Ansible Playbooks, building, testing, scanning with SonarQube and Fortify, and storing the artifact in JFrog Artifactory. 

Below are the detailed steps along with the required Jenkinsfile, Ansible playbook, and information on the necessary credentials.

Prerequisites

  1. Jenkins Setup:

    • Jenkins should be installed and configured.
    • Plugins: Ansible, SonarQube Scanner, Fortify, JFrog Artifactory.
  2. Credentials:

    • Ansible: SSH Key for Red Hat Server.
    • SonarQube: API Token.
    • Fortify: API Token.
    • JFrog Artifactory: Username and API Key.
  3. Tools:

    • Ansible installed and configured on Jenkins.
    • SonarQube and Fortify servers accessible from Jenkins.
    • JFrog Artifactory accessible from Jenkins.

Jenkins Pipeline Script (Jenkinsfile)

groovy
pipeline { agent any environment { ANSIBLE_PLAYBOOK = 'reboot-server.yml' ANSIBLE_INVENTORY = 'hosts' SONARQUBE_SERVER = 'sonarqube.example.com' SONARQUBE_TOKEN = credentials('sonarqube-token') FORTIFY_SERVER = 'fortify.example.com' FORTIFY_TOKEN = credentials('fortify-token') ARTIFACTORY_SERVER = 'artifactory.example.com' ARTIFACTORY_CREDENTIALS = credentials('artifactory-credentials') } stages { stage('Reboot Server') { steps { script { ansiblePlaybook( playbook: "${ANSIBLE_PLAYBOOK}", inventory: "${ANSIBLE_INVENTORY}", extras: "--become --extra-vars '
ansible_become_pass=${env.ANSIBLE_SSH_PASS}'" ) } } } stage('Build') { steps { // Replace with your build steps, e.g., Maven, Gradle echo 'Building the application...' } } stage('Test') { steps { // Replace with your testing steps echo 'Running tests...' } } stage('SonarQube Scan') { environment { SONARQUBE_URL = "${SONARQUBE_SERVER}" } steps { withSonarQubeEnv('SonarQube') { sh 'sonar-scanner -Dsonar.projectKey=my_project
-Dsonar.sources=. -Dsonar.host.url=${SONARQUBE_URL}
-Dsonar.login=${SONARQUBE_TOKEN}' } } } stage('Fortify Scan') { steps { script { // Assuming Fortify command-line tools are
installed and configured sh "sourceanalyzer -b my_project -scan -f
my_project.fpr -url ${FORTIFY_SERVER} -token ${FORTIFY_TOKEN}" } } } stage('Artifact Storage') { steps { script { // Replace with your artifact storage steps sh "curl -u ${ARTIFACTORY_CREDENTIALS} -T
./path/to/your/artifact.ext https://${ARTIFACTORY_SERVER}/
artifactory/path/to/repo/" } } } } post { always { cleanWs() } } }

Ansible Playbook (reboot-server.yml)

yaml
--- - name: Reboot Red Hat Server hosts: all become: yes tasks: - name: Reboot the server ansible.builtin.reboot: reboot_timeout: 300

Inventory File (hosts)

css
[all] redhat-server-1 ansible_host=your.server.ip ansible_user=your_ssh_user
ansible_ssh_private_key_file=/path/to/ssh_key

Adding Credentials in Jenkins

  1. Ansible SSH Key:

    • Go to Jenkins Dashboard > Credentials > System > Global credentials (unrestricted).
    • Add a new credential of type "SSH Username with private key".
    • Add your SSH key file for the Red Hat Server.
  2. SonarQube Token:

    • Go to Jenkins Dashboard > Credentials > System > Global credentials (unrestricted).
    • Add a new credential of type "Secret text".
    • Enter your SonarQube API token.
  3. Fortify Token:

    • Repeat the same steps as for the SonarQube Token, but use your Fortify API token.
  4. JFrog Artifactory Credentials:

    • Add a new credential of type "Username with password".
    • Enter your Artifactory username and API key.

Summary

This Jenkins pipeline script is designed to:

  1. Reboot a Red Hat Server 9 using Ansible.
  2. Build the application (customise the build steps according to your project).
  3. Run tests (customise the test steps according to your project).
  4. Perform a SonarQube scan for code quality analysis.
  5. Perform a Fortify scan for security analysis.
  6. Upload the artifact to JFrog Artifactory.

Make sure to replace placeholder steps with your actual build and test commands, and ensure that your Jenkins environment is configured correctly with the necessary tools and credentials.

How to Master the Perfect ChatGPT Prompt Formula (in just 8 minutes)!

Imagine having the power to get the exact response you need from ChatGPT —every time. Whether you’re looking for writing help, coding assi...