Automating Initial Server Setup on Rocky Linux 9 with Ansible: A Step-by-Step Guide

Introduction:

Automating the initial server setup process is crucial for efficiently managing and configuring multiple servers. Ansible, a popular open-source automation tool, enables system administrators to automate various tasks, including server provisioning, configuration management, and deployment. In this article, we will guide you through the process of using Ansible to automate the initial server setup on Rocky Linux 9.

Step 1: Install Ansible:

Before getting started, ensure that Ansible is installed on your local machine. If it is not installed, follow the appropriate installation instructions for your operating system. For example, on a Debian-based system, you can install Ansible using the following command:

sudo apt-get install ansible

Step 2: Configure the Inventory:

The inventory file in Ansible contains information about the servers you want to manage. Open a text editor and create an inventory file, for example, inventory.ini, and add the IP addresses or hostnames of your Rocky Linux 9 servers:

[webservers]
server1 ansible_host=192.168.0.1
server2 ansible_host=192.168.0.2

Save and close the inventory file.

Step 3: Create the Playbook:

Ansible uses playbooks to define automation tasks. Create a new playbook file, for example, setup.yml, using a text editor. This playbook will automate the initial server setup tasks. Add the following content to the playbook:

---
- name: Initial Server Setup
  hosts: webservers
  become: true

  tasks:
    - name: Update Packages
      package:
        name: "*"
        state: latest
      register: package_update

    - name: Install Additional Packages
      package:
        name:
          - package1
          - package2
        state: present

    - name: Configure Firewall
      firewalld:
        service: http
        permanent: true
        state: enabled

    - name: Enable and Start Services
      systemd:
        name:
          - service1
          - service2
        state: started
        enabled: true

Adjust the tasks according to your requirements. For example, you can add tasks to create users, configure SSH, install specific packages, or perform other initial setup tasks.

Save and close the playbook file.

Step 4: Run the Playbook:

To execute the playbook and automate the initial server setup, run the following command in the terminal:

ansible-playbook -i inventory.ini setup.yml

Ansible will connect to the servers defined in the inventory file and execute the tasks specified in the playbook.

Step 5: Verify the Server Setup:

After the playbook execution completes, log in to your Rocky Linux 9 servers and verify that the initial server setup tasks have been automated successfully. Check if the packages are updated, additional packages are installed, the firewall is configured, and the required services are running.

Conclusion:

By using Ansible, you can automate the initial server setup process on Rocky Linux 9, saving time and ensuring consistency across your server infrastructure. With the step-by-step guide provided in this article, you can leverage the power of Ansible to streamline your server provisioning and configuration management workflows. Customize the playbook to fit your specific requirements, and enjoy the benefits of automated server setup with Ansible.


Related Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *