Ansible is an open-source automation tool that simplifies the configuration and management of IT infrastructure. It can be easily installed on CentOS 7 or RHEL 7 by following the steps below:

Step 1: Update the System Before installing Ansible, make sure the system is up-to-date. To do this, run the following command:

sudo yum update -y

Step 2: Install the EPEL Repository
Ansible requires the EPEL (Extra Packages for Enterprise Linux) repository to be installed. To install the EPEL repository, run the following command:

sudo yum install epel-release -y

Step 3: Install Ansible
Once the EPEL repository is installed, you can install Ansible using the following command:

sudo yum install ansible -y

Step 4: Verify the Installation
After the installation is complete, you can verify that Ansible is working by running the following command:

ansible --version

This command should display the version of Ansible installed on the system.

Step 5: Configure SSH Access Ansible uses SSH to connect to remote hosts, so make sure that SSH access is enabled on the remote hosts. You can also configure SSH access for the user that will run Ansible by generating an SSH key pair and copying the public key to the remote hosts. To generate an SSH key pair, run the following command:

ssh-keygen

Step 6: Configure the Inventory The inventory file is a list of hosts that Ansible will manage. By default, Ansible uses the /etc/ansible/hosts file as the inventory. You can add hosts to this file manually, or you can use dynamic inventories that generate the host list based on various criteria.

Step 7: Create a Playbook Ansible playbooks define the tasks that need to be performed on the managed hosts. Playbooks are written in YAML format and can be easily customized to suit your needs. You can create a simple playbook to install a package using the following code:

---
- name: Install Package
  hosts: web-servers
  become: true
  tasks:
    - name: Install Package
      yum:
        name: httpd
        state: present

This playbook will install the httpd package on the hosts specified in the inventory file.

Step 8: Execute the Playbook To execute the playbook, run the following command:

ansible-playbook playbook.yml

This command will connect to the hosts specified in the inventory file and execute the tasks defined in the playbook.

Overall, installing and setting up Ansible on CentOS 7 or RHEL 7 is a simple process that can be completed in just a few steps. Once installed, Ansible can help you automate a wide range of IT infrastructure management tasks, making it a valuable tool for IT professionals.

Categorized in: