Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. 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 28 July 2017

Reset Your Forgotten Ubuntu Password in 2 Minutes or Less





If you’ve ever forgotten your password, you aren’t alone… it’s probably one of the most common tech support problems I’ve encountered over the years. Luckily if you are using Ubuntu they made it incredibly easy to reset your password.
image
All it takes is adjusting the boot parameters slightly and typing a command or two, but we’ll walk you through it.
Reset Your Ubuntu Password
Reboot your computer, and then as soon as you see the GRUB Loading screen, make sure to hit the ESC key so that you can get to the menu.
image
Root Shell – Easy Method
If you have the option, you can choose the “recovery mode” item on the menu, usually found right below your default kernel option.
image[3]
Then choose “Drop to root shell prompt” from this menu.
image[6]
This should give you a root shell prompt.
Alternate Root Shell Method
If you don’t have the recovery mode option, this is the alternate way to manually edit the grub options to allow for a root shell.
First you’ll want to make sure to choose the regular boot kernel that you use (typically just the default one), and then use the “e” key to choose to edit that boot option.
image
Now just hit the down arrow key over to the “kernel” option, and then use the “e” key to switch to edit mode for the kernel option.
image
You’ll first be presented with a screen that looks very similar to this one:
image
You’ll want to remove the “ro quiet splash” part with the backspace key, and then add this onto the end:
rw init=/bin/bash
image
Once you hit enter after adjusting the kernel line, you’ll need to use the B key to choose to boot with that option.
image
At this point the system should boot up very quickly to a command prompt.
Changing the Actual Password
You can use the following command to reset your password:
passwd <username>
For example my username being geek I used this command:
passwd geek
image
After changing your password, use the following commands to reboot your system. (The sync command makes sure to write out data to the disk before rebooting)
sync
reboot –f
I found that the –f parameter was necessary to get the reboot command to work for some reason. You could always hardware reset instead, but make sure to use the sync command first.
And now you should be able to login without any issues.

Tuesday 1 October 2013

How to Install Ruby & Rails on CentOS, Fedora or RedHat

#get root access
$su -
$ cd /tmp
 
#Remove old Ruby
$ yum remove ruby
# Install dependencies
$ yum groupinstall "Development Tools"
$ yum install zlib zlib-devel
$ yum install openssl-devel
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ tar xzvf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4
$ ./configure
$ make
$ make install
# Install ruby
$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
$ tar zxf ruby-1.9.3-p194.tar.gz
$ cd ruby-1.9.3-p194
$ ./configure
$ make
$ make install
# Update rubygems
$ gem update --system
$ gem install bundler
#Test ruby and rubygems are working
#Close shell and reopen for changes to take effect
$ruby -v
$gem --version
# Rails
$ yum install sqlite-devel
$ gem install rails
$ gem install sqlite3

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 ...