Showing posts with label DevOps. Show all posts
Showing posts with label DevOps. Show all posts

Thursday 25 April 2024

How to Create a Ansible Lab on your Local Machine using Vagrant in 5 min using ChatGPT


This is an exciting experiment of mine as DevOps. As I am experimenting with the Tools available ... So, the quest is to "Vagrantfile which creates 3 instances of Centos 8 servers, each server shall be able to connect on the same network for easy communication"

Here is what we want to achieve:

- Build 3 servers to use Ansible

Jumped into via ChatGPT via Bing Copilot and created the following prompt.


"Hi Copilot, can you write a Vagrantfile which creates 3 instances of Centos 8 servers, each server shall be able to connect on the same network for easy communication, these instance serves are to be used as Ansible Lab environments comprised of one Ansible Tower and two deployments environments, please"


The output:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # Define the base box
  config.vm.box = "centos/8"

  # Ansible Tower Server
  config.vm.define "ansible_tower" do |ansible_tower|
    ansible_tower.vm.hostname = "ansible-tower"
    ansible_tower.vm.network "private_network", ip: "192.168.56.10"
  end

  # Deployment Environment 1
  config.vm.define "deploy_env1" do |deploy_env1|
    deploy_env1.vm.hostname = "deploy-env1"
    deploy_env1.vm.network "private_network", ip: "192.168.56.11"
  end

  # Deployment Environment 2
  config.vm.define "deploy_env2" do |deploy_env2|
    deploy_env2.vm.hostname = "deploy-env2"
    deploy_env2.vm.network "private_network", ip: "192.168.56.12"
  end

  # Provisioning with Ansible (Optional)
  # config.vm.provision "ansible" do |ansible|
  #   ansible.playbook = "playbook.yml"
  # end
end

Source code on Git Hub repository.

To use this Vagrantfile:

  1. Install VirtualBox and Vagrant on your system.
  2. Save the above code into a file named Vagrantfile.
  3. Open a terminal and navigate to the directory containing the Vagrantfile.
  4. Run vagrant up to create the VMs.

This Vagrantfile configures each CentOS 8 server with a static IP on a private network, allowing them to communicate with each other. You can uncomment and adjust the Ansible provisioning block to run your Ansible playbooks automatically.

You’ll have three CentOS 8 servers (server1, server2, and server3) along with an Ansible Tower instance (ansible-tower) for your lab environment. Adjust memory and CPU settings as needed based on your system resources.

Happy Ansible-ing! 🚀

Next - 

To test the Ansible connection to the three CentOS 8 servers you've set up, you can use a simple Ansible playbook that employs the ping module. This module is specifically designed for connection testing and doesn't actually send ICMP pings but attempts an SSH connection and returns pong on success.

Here's an example playbook, test_connection.yml, that you can use:


yaml
--- - name: Test Ansible Connection to Servers hosts: all gather_facts: no tasks: - name: Test connectivity with ping module ansible.builtin.ping:

Before running the playbook, ensure you have an inventory file (inventory.ini or your preferred name) that lists the IPs or hostnames of your servers under a group [servers] or individually. Here's an example:

javascript
[servers] 192.168.56.10 ansible_user=your_username ansible_ssh_private_key_file=/path/to/private_key 192.168.56.11 ansible_user=your_username ansible_ssh_private_key_file=/path/to/private_key 192.168.56.12 ansible_user=your_username ansible_ssh_private_key_file=/path/to/private_key


Replace your_username and /path/to/private_key with the appropriate user and SSH key path for your setup.

To run the playbook and test the connection to all servers in your inventory, use the following command:

bash
ansible-playbook -i inventory.ini test_connection.yml

This command will attempt to connect to each server listed in inventory.ini and report back whether the connection was successful.
....

Nice !! Now, let us push this code further ..  I have tested the script on my machine and Made all 3 instances up and running.  Further improved the code and stored in Github source code here

Here the code on VisualCode:


Continue on  part 2


🌐 Sourcesmedium.com - How to Create Multiple Virtual Machines Using Vagrant Tool

stackoverflow.com - Two Operating Systems in a single Vagrantfile



Friday 19 April 2024

Secure Your Azure DevOps Pipeline: GitHub Advanced Security to the Rescue

 

Stop Shipping Your Passwords to Production: How GitHub Advanced Security for Azure DevOps Saves the Day (and Your Reputation)


Let's face it, developers: we've all accidentally committed a secret (or two) to our code repository at some point. Maybe it was an API key, a database password, or that super-secret encryption key you swore you'd never forget. ‍♂️

The problem? Those exposed secrets can be a hacker's dream come true. A single leaked secret can bring your entire application crashing down, wreaking havoc on your data and your reputation. Shuddersville.


That's where GitHub Advanced Security for Azure DevOps swoops in like a superhero with a cape (well, maybe more like a shield, but you get the idea). This powerful integration brings the muscle of GitHub's security features right into your Azure DevOps workflow, so you can identify and squash those secret leaks before they turn into a disaster.




Here's how GitHub Advanced Security for Azure DevOps saves your bacon:

  • Secret Scanning: It acts like a super-sleuth, scouring your code for any exposed secrets like passwords, tokens, and keys. No more accidental oopsies making it past your commit.
  • Dependency Scanning: Those third-party libraries you love? They can have hidden vulnerabilities. Advanced Security scans your dependencies to expose any weak spots so you can patch them up before they get exploited.
  • CodeQL Code Scanning: This built-in code analysis tool is like a security X-ray for your codebase. It hunts for potential vulnerabilities and coding errors, so you can fix them before they become a problem.

The best part? This security suite integrates seamlessly into your Azure DevOps workflow. No need to jump through hoops or learn a whole new platform. You can find, fix, and prevent security issues all within your familiar Azure DevOps environment. Win-win!


So, ditch the stress of exposed secrets and vulnerable code. Embrace the power of GitHub Advanced Security for Azure DevOps. Your future self (and your security team) will thank you for it.

P.S. Looking for more info? Check out the official documentation to see how to get started with GitHub Advanced Security for Azure DevOps and start building more secure software today!


How to Create a Ansible Lab on your Local Machine using Vagrant in 5 min using ChatGPT

This is an exciting experiment of mine as DevOps. As I am experimenting with the Tools available ... So, the quest is to " Vagrantfile ...