Automating Neofetch Installation and Configuration using Ansible

image_print

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!

You may also like...