Automating Neofetch Installation and Configuration using Ansible

Introduction:
Neofetch is a simple and visually appealing command-line system information tool. By using Ansible, we can automate the installation of Neofetch and its configuration, including adding it to the .bashrc file and displaying the Raspberry Pi’s temperature. In this guide, we’ll walk you through creating an Ansible playbook to achieve this automation.

Step 1: Install Ansible
Before proceeding, make sure you have Ansible installed on your system. If you haven’t installed Ansible yet, you can follow the official Ansible installation instructions for your operating system.

Step 2: Create the Ansible Playbook
Create a new YAML file named neofetch_setup.yaml and add the following content to it:

---
- name: Install Neofetch and update .bashrc
  hosts: your_host  # Replace "your_host" with the target host or group where you want to install Neofetch.
  become: yes

  tasks:
    - name: Install Neofetch
      apt:
        name: neofetch
        state: present

    - name: Add Neofetch to .bashrc
      blockinfile:
        path: ~/.bashrc
        block: |
          if [[ -z $(grep -Fxq "neofetch" ~/.bashrc) ]]; then
              echo "neofetch" >> ~/.bashrc
          fi

    - name: Add vcgencmd measure_temp to .bashrc
      blockinfile:
        path: ~/.bashrc
        block: |
          if [[ -z $(grep -Fxq "vcgencmd measure_temp" ~/.bashrc) ]]; then
              echo "vcgencmd measure_temp" >> ~/.bashrc
          fi

In the playbook, make sure to replace “your_host” with the target host or group where you want to install Neofetch. Also, ensure that your target host has the necessary privileges (sudo access) to install packages and modify the .bashrc file.

Step 3: Run the Ansible Playbook
To run the Ansible playbook and install Neofetch on the target host, use the following command:

ansible-playbook neofetch_setup.yaml

Ansible will connect to the target host, install Neofetch, and update the .bashrc file with the appropriate commands.

Step 4: Verify Neofetch Installation
To verify that Neofetch is installed and configured correctly, log in to the target host and open a new terminal. You should see the Neofetch output displaying system information. Additionally, the Raspberry Pi’s temperature will be displayed along with the system details.

Conclusion:
You’ve successfully created an Ansible playbook to automate the installation of Neofetch and its configuration on your Raspberry Pi. Ansible allows you to manage multiple hosts efficiently and ensure consistent setups across your infrastructure. Now you can enjoy using Neofetch to get a stylish system summary each time you open a terminal.

Happy system information tracking!




Setting Up a Minecraft Server with Docker

Introduction:
Minecraft is a popular sandbox video game, and with Docker, you can easily create and manage a Minecraft server. Docker allows you to encapsulate the server environment, making it easy to deploy and maintain. In this guide, we’ll show you how to set up a Minecraft server using Docker and configure its settings.

Step 1: Install Docker
Before proceeding, ensure you have Docker installed on your system. If you haven’t installed Docker yet, follow the official Docker installation instructions for your operating system.

Step 2: Pull the Minecraft Server Docker Image
To run the Minecraft server, pull the latest Minecraft Server Docker image from Docker Hub using the following command:

docker pull itzg/minecraft-server:latest

Step 3: Create and Start the Minecraft Server Container
Run the following command to create and start the Minecraft server container:

docker run -d -it --name minecraft -v minecraft_data:/data -p 25565:25565 -e EULA=TRUE -e MODE=creative -e MEMORY=2G -e tty=true --restart always itzg/minecraft-server:latest

Explanation of options used:

  • -d: Run the container in the background (detached mode).
  • -it: Allocate a pseudo-TTY and keep STDIN open, allowing you to interact with the server console.
  • --name minecraft: Assign the name “minecraft” to the container for easy management.
  • -v minecraft_data:/data: Create a Docker volume named “minecraft_data” and mount it to the /data directory inside the container. This volume allows you to persist Minecraft world data and configurations.
  • -p 25565:25565: Map port 25565 from the container to the host system. This is the default port for Minecraft servers.
  • -e EULA=TRUE: Accept the Minecraft End User License Agreement (EULA).
  • -e MODE=creative: Set the server mode to “creative.” You can change this to “survival” or other valid game modes.
  • -e MEMORY=2G: Set the allocated memory for the server to 2GB. Adjust this value based on your server’s requirements.
  • -e tty=true: Enable the TTY (Terminal) for interacting with the server console.
  • --restart always: Configure the container to automatically restart if it stops unexpectedly.

Step 4: Access the Minecraft Server Console
To access the Minecraft server console interactively, use the following command:

docker attach minecraft

This command will attach your current terminal to the running Minecraft server container, providing you with an interactive console to manage the server.

Step 5: Clean Up
If you want to stop and remove the Minecraft server container and the associated volume, use the following commands:

docker stop minecraft
docker rm minecraft
docker volume rm minecraft_data

Conclusion:
You’ve successfully set up a Minecraft server using Docker, allowing you to host and manage your Minecraft world easily. Docker’s portability and isolation make it a convenient choice for running a Minecraft server without interfering with your host system. Enjoy playing and exploring your Minecraft creations!

Happy mining!




Running Kali Linux in a Docker Container

Introduction:
Kali Linux is a popular penetration testing and ethical hacking distribution. With Docker, you can run Kali Linux in a containerized environment, making it easy to experiment and perform security assessments. In this guide, we’ll show you how to run Kali Linux as a Docker container and access it interactively.

Step 1: Install Docker
Before proceeding, make sure you have Docker installed on your system. If you haven’t installed Docker yet, follow the official Docker installation instructions for your operating system.

Step 2: Pull Kali Linux Docker Image
To run Kali Linux, pull the latest Kali Linux Docker image from Docker Hub using the following command:

docker pull kalilinux/kali-rolling

Step 3: Create and Start Kali Linux Container
Run the following command to create and start a Kali Linux container:

docker run -d --name=kalilinux -v kalilinux_data:/data --tty --interactive kalilinux/kali-rolling

Explanation of options used:

  • -d: Run the container in the background (detached mode).
  • --name=kalilinux: Assign the name “kalilinux” to the container for easy management.
  • -v kalilinux_data:/data: Create a Docker volume named “kalilinux_data” and mount it to the /data directory inside the container. This volume allows you to persist data and configuration between container restarts.
  • --tty: Allocate a pseudo-TTY, which enables interactive access to the container’s terminal.
  • --interactive: Keep STDIN open even if not attached. This allows you to interact with the container’s terminal.

Step 4: Access the Kali Linux Container
To access the Kali Linux container interactively, use the following command:

docker exec -it kalilinux bash

This command will attach your current terminal to the running Kali Linux container, providing you with an interactive shell inside the container.

Step 5: Clean Up
If you want to stop and remove the Kali Linux container and the associated volume, use the following commands:

docker stop kalilinux
docker rm kalilinux
docker volume rm kalilinux_data

Conclusion:
You’ve successfully run Kali Linux in a Docker container, allowing you to perform security assessments and penetration testing in an isolated environment. Docker enables easy management and deployment of Kali Linux, making it an excellent choice for testing and experimenting with various tools and configurations.

Happy hacking!




Installing Jellyfin Media Server with Docker

Introduction:
Jellyfin is an open-source media server that allows you to organize, stream, and access your media content from various devices. By using Docker, we can easily set up Jellyfin and manage its configuration and data in isolated containers. In this guide, we’ll show you how to install Jellyfin using Docker and ensure it starts automatically.

Step 1: Install Docker
Before proceeding, ensure you have Docker installed on your system. If you haven’t installed Docker yet, follow the official Docker installation instructions for your operating system.

Step 2: Pull Jellyfin Docker Image
To install Jellyfin, pull the latest Docker image from Docker Hub using the following command:

docker pull jellyfin/jellyfin:latest

Step 3: Create a Docker Container for Jellyfin
Run the following command to create a Docker container for Jellyfin with proper volume and network configurations:

docker run -d --restart always --name jellyfin -v jellyfin_config:/config -v jellyfin_cache:/cache -v jellyfin_media:/media --net=host jellyfin/jellyfin:latest

Explanation of options used:

  • -d: Run the container in the background (detached mode).
  • --restart always: Configure the container to automatically restart if it stops unexpectedly.
  • --name jellyfin: Assign the name “jellyfin” to the container for easy management.
  • -v jellyfin_config:/config: Create a Docker volume named “jellyfin_config” to persist the Jellyfin configuration data.
  • -v jellyfin_cache:/cache: Create a Docker volume named “jellyfin_cache” to store the Jellyfin cache data.
  • -v jellyfin_media:/media: Create a Docker volume named “jellyfin_media” to mount your media content.
  • --net=host: Use the host’s network stack to simplify network configuration and improve performance.

Step 4: Access Jellyfin
Once the Jellyfin container is running, you can access the Jellyfin web interface by opening a web browser and navigating to http://localhost:8096. From here, you can set up Jellyfin and start adding your media libraries.

Step 5: Clean Up
If you want to stop and remove the Jellyfin container and volumes, use the following commands:

docker stop jellyfin
docker rm jellyfin
docker volume rm jellyfin_config jellyfin_cache jellyfin_media

Conclusion:
You’ve successfully installed Jellyfin media server using Docker, providing a powerful platform to organize and stream your media content across devices. Docker allows you to manage Jellyfin in an isolated and portable environment, ensuring easy setup and deployment. Enjoy exploring Jellyfin’s features and transforming your Raspberry Pi into a media powerhouse!

Happy media streaming!




Setting Up Drupal with Docker Compose

Introduction:
Drupal is a popular content management system that allows you to create and manage websites with ease. By using Docker, we can quickly set up Drupal along with its MariaDB database, making the deployment process straightforward and portable. In this guide, we’ll show you how to run Drupal and MariaDB containers with Docker Compose.

Step 1: Install Docker and Docker Compose
Before proceeding, ensure you have Docker and Docker Compose installed on your system. If not, follow the official Docker installation instructions for your operating system.

Step 2: Create a Docker Compose File
Create a new directory for your Drupal project and navigate into it:

mkdir drupal_project
cd drupal_project

Inside the drupal_project directory, create a docker-compose.yml file using a text editor of your choice (e.g., nano, vi, or vim), and add the following content:

version: '3'

services:
  drupaldb:
    image: mariadb:latest
    environment:
      MYSQL_ROOT_PASSWORD: drupal
      MYSQL_DATABASE: drupal
    volumes:
      - drupal_mariadb_data:/var/lib/mysql
    container_name: drupaldb
    restart: always

  drupal:
    image: drupal:latest
    ports:
      - "80:80"
    environment:
      DRUPAL_DB_USER: root
      DRUPAL_DB_PASSWORD: drupal
    volumes:
      - drupal_data:/var/www/html
    container_name: drupal
    depends_on:
      - drupaldb
    restart: always

volumes:
  drupal_mariadb_data:
  drupal_data:

Save the file and exit the editor.

Step 3: Start the Containers
To create and start the Drupal and MariaDB containers, run the following command inside the drupal_project directory:

docker-compose up -d

Docker Compose will pull the required images (if not already available locally) and start the containers in the background.

Step 4: Access Drupal
Once the containers are running, you can access your Drupal site by opening a web browser and navigating to http://localhost. The Drupal installation wizard will guide you through the setup process.

Step 5: Cleanup
If you want to stop and remove the containers and volumes created by Docker Compose, use the following command:

docker-compose down

Conclusion:
Congratulations! You’ve successfully set up Drupal with Docker Compose, providing a scalable and easily manageable environment for your website. Docker Compose simplifies the process of managing multi-container applications, making it ideal for running Drupal alongside its MariaDB database. Now you can focus on building your Drupal website without worrying about the complexities of server setup.

Happy Drupal development!




Automating Raspberry Pi Configuration with Ansible

Introduction:
Managing multiple Raspberry Pi devices can be time-consuming and error-prone if done manually. Fortunately, Ansible provides a powerful solution for automating configuration tasks across your Raspberry Pi fleet. In this guide, we’ll walk you through setting up Ansible, creating an inventory, and using playbooks to perform various tasks on your Raspberry Pi devices.

Prerequisites:
Before proceeding, make sure you have Python3 and pip installed on your Raspberry Pi. You can install pip using the following command:

sudo apt install python3-pip

Step 1: Install Ansible
First, let’s install Ansible using pip:

python3 -m pip install --user ansible-core==2.12.3

Step 2: Create Ansible Configuration
Now, create a directory for your Ansible project and add an ansible.cfg file inside it:

mkdir /ansible
vi /ansible/ansible.cfg

Paste the following configuration in the ansible.cfg file:

[defaults]
inventory = inventory
host_key_checking = False

Save the file and exit the editor.

Step 3: Create the Inventory
The inventory file contains information about the hosts (Raspberry Pi devices) you want to manage. Create an inventory file inside the /ansible directory:

vi /ansible/inventory

Add the following content to the inventory file:

[tower]
RPIT1 ansible_host=192.168.0.220
RPIT2 ansible_host=192.168.0.221
RPIT3 ansible_host=192.168.0.222
RPTT4 ansible_host=192.168.0.223

[test]
RPI2GB ansible_host=192.168.0.227

[docker]
RPIDOCKER ansible_host=192.168.0.224

[kali]
RPIKALI ansible_host=192.168.0.226

[zeros]
RPIZEROW ansible_host=192.168.0.228 
RPIZEROW2 ansible_host=192.168.0.225

[all:vars]
ansible_ssh_user=pi ansible_ssh_pass=xxxxxxxxx

This inventory defines groups of hosts (towers, test, docker, kali, and zeros) and sets the SSH username and password to access them.

Step 4: Test Host Reachability
Before proceeding with any configuration, make sure all defined hosts are reachable using Ansible’s ping module:

ansible all -m ping

Step 5: Check OS Information
Retrieve OS information on all clients using the shell module:

ansible all -m shell -a "lsb_release -a"

Step 6: Upgrade Servers
Use a playbook to upgrade all servers:

ansible-playbook -e "target_host=all" update_upgrade.yaml

Step 7: Install Neofetch and Temperature
Create a playbook to install Neofetch and display the system temperature:

ansible-playbook -e "target_host=all" install_neofetch.yaml

Step 8: Shutdown the Tower
Create a playbook to shut down the tower (remember Docker always on):

ansible-playbook -e "target_host=tower" shutdown_now.yaml

Conclusion:
You’ve successfully set up Ansible and used playbooks to automate tasks on your Raspberry Pi devices. Ansible simplifies managing multiple devices and allows you to perform configurations efficiently and consistently. With Ansible, you can now spend less time on repetitive tasks and focus more on your Raspberry Pi projects.

Happy automating!




Installing Docker Compose on Raspberry Pi

Introduction:
With Docker Compose, you can define and run multi-container Docker applications easily. In this guide, we’ll walk you through the steps to install Docker Compose on your Raspberry Pi, so you can manage complex applications using Docker containers effortlessly.

Prerequisites:
Before proceeding with the installation, make sure you have Docker already installed on your Raspberry Pi. If not, please refer to our previous blog post on “Setting up Docker on Raspberry Pi” to get Docker up and running.

Step 1: Update Your System
As a best practice, always update your package lists before installing any new software. Run the following command to update your Raspberry Pi:

sudo apt update

Step 2: Install Docker Compose
Docker Compose can be installed using pip, the Python package manager. To install pip on your system, run the following command:

sudo apt install python3-pip

Once pip is installed, you can proceed to install Docker Compose:

sudo pip3 install docker-compose

Step 3: Verify Installation
After the installation is complete, verify that Docker Compose is installed and accessible by checking its version:

docker-compose --version

This command will display the version of Docker Compose if the installation was successful.

Step 4: Test Docker Compose
Now that Docker Compose is installed, you can test it by creating a simple Docker Compose file and running a container.

Create a new directory and navigate into it:

mkdir docker_test
cd docker_test

Create a docker-compose.yml file using a text editor of your choice (e.g., nano, vi, or vim) with the following contents:

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"

Save the file and exit the editor.

Run the following command to start the Nginx web server using Docker Compose:

docker-compose up -d

Step 5: Test the Web Server
To verify that the Nginx web server is running, open a web browser and enter your Raspberry Pi’s IP address. You should see the default Nginx welcome page.

Step 6: Stop and Remove Containers
To stop and remove the containers defined in your docker-compose.yml file, run the following command:

docker-compose down

Conclusion:
Congratulations! You have successfully installed Docker Compose on your Raspberry Pi, allowing you to manage multi-container applications effortlessly. With Docker Compose, you can define complex services and their dependencies in a single file, making it easier to deploy and manage your applications. Enjoy experimenting with Docker Compose and exploring the world of containerized applications on your Raspberry Pi.

Happy containerizing!




Setting up Docker on Raspberry Pi: A Step-by-Step Guide

Introduction:
Raspberry Pi is a versatile mini-computer, and with the growing popularity of containerization, using Docker on a Raspberry Pi can open up exciting possibilities. In this guide, we will walk you through the steps to set up Docker on your Raspberry Pi so that you can leverage the power of containerization for your projects.

Before you start:
Make sure you have a Raspberry Pi up and running with the Raspbian OS or its derivatives. Additionally, ensure you have a stable internet connection to proceed with the installation.

Step 1: Editing cmdline.txt
To enable memory control and avoid issues with mem management, we need to make some adjustments to the cmdline.txt file. Open the file using the following command:

sudo vi /boot/cmdline.txt

Add the following lines at the end of the file:

cgroup_enable=memory swapaccount=1 cgroup_memory=nokmem cgroup_enable=cpuset

Save the changes and exit the editor.

Step 2: Adjusting GPU memory
To ensure smooth performance with Docker, it is recommended to allocate at least 128MB of GPU memory. Use the following steps to make the adjustment:

  • Open the raspi-config tool:
sudo raspi-config

  • Navigate to “Advanced Options” and then “Memory Split.”
  • Set the GPU memory to 128MB.
  • Save the changes and exit the configuration tool.

Step 3: Updating your system
Before installing Docker, it’s essential to have your system up-to-date. Run the following commands to update your Raspberry Pi:

sudo apt update
sudo apt upgrade -y
sudo rpi-update
sudo reboot
sudo rpi-eeprom-update -a
sudo reboot

Step 4: Installing Docker
Now, it’s time to install Docker on your Raspberry Pi. Execute the following commands:

sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo reboot

Step 5: Granting permissions for Docker
To run Docker commands without using sudo, add your user to the “docker” group:

sudo groupadd docker
sudo usermod -aG docker $USER

Make sure to log out and log back in to apply the changes.

Conclusion:
Congratulations! You have successfully set up Docker on your Raspberry Pi, allowing you to harness the power of containerization for your projects. Docker provides an efficient way to manage applications and services, making development and deployment a breeze on your Raspberry Pi. Enjoy exploring the world of containers and unleash the full potential of your tiny yet powerful computing companion.

Happy coding!