Ansible is a powerful automation tool widely used for configuration management and application deployment. Here’s the step by step tutorial about how to install Ansible on CentOS 7.
Updating System Packages
Start by updating the system packages:
sudo yum update -y
Enabling the EPEL Repository
Ansible is available in the Extra Packages for Enterprise Linux (EPEL) repository. Enable EPEL using:
sudo yum install epel-release -y
Installing Ansible
Now, install Ansible:
sudo yum install ansible -y
Verifying Ansible Installation
Check the installed version of Ansible:
ansible --version
Configuring Ansible
1. Ansible uses SSH for communication with remote hosts. Ensure SSH is installed:
sudo yum install openssh-server openssh-clients -y
2. Configure SSH keys for password-less authentication with managed nodes.
Testing Ansible
Test your setup by running a simple Ansible command, such as pinging a localhost:
ansible localhost -m ping
You have successfully installed Ansible on CentOS 7. You can now automate tasks and manage your infrastructure efficiently using Ansible playbooks. For advanced configurations, consider setting up Ansible roles, inventories, and custom modules as needed for your environment.
Ansible Tower
Download the latest Ansible Tower package from the official website. Alternatively, use `wget`:
wget https://releases.ansible.com/ansible-tower/setup/ansible-tower-setup-latest.tar.gz
Extracting the Installer
Extract the downloaded file:
tar xvfz ansible-tower-setup-latest.tar.gz
Navigate to the extracted directory:
cd ansible-tower-setup-*
Configuring Ansible Tower
1. Edit the `inventory` file in the directory to configure your Ansible Tower settings. You can specify the PostgreSQL database settings, admin password, etc.
sudo vi inventory
2. Modify the settings as per your requirements.
Running the Ansible Tower Setup
Run the setup script:
sudo ./setup.sh
This script will install and configure Ansible Tower.
Verifying the Installation
Once the setup is complete, access Ansible Tower via a web browser using your server’s IP address or domain name on port 80 or 443.
Ansible AWX
Ansible AWX is the open-source version of Ansible Tower, providing a web-based user interface for Ansible.
Installing Docker and Docker Compose
1. Install Docker:
sudo yum install docker -y
2. Start and enable Docker:
sudo systemctl start docker sudo systemctl enable docker
3. Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Cloning the AWX Repository
Clone the AWX GitHub repository:
git clone https://github.com/ansible/awx.git cd awx/installer/
Installing Ansible AWX
1. Edit the `inventory` file to configure your AWX installation:
vi inventory
Adjust configurations like PostgreSQL data persistence, admin password, etc.
2. Run the Ansible Playbook to install AWX:
ansible-playbook -i inventory install.yml
Accessing Ansible AWX
Once the installation is complete, access AWX through your web browser using your server’s IP address, typically on port 80.
Using Ansible Galaxy
Ansible Galaxy is a repository for Ansible Roles, which are pre-packaged, reusable sets of Ansible tasks.
1. Ansible Galaxy is accessed via the command line using the `ansible-galaxy` command.
2. Searching for Roles:
ansible-galaxy search [role_name]
3. Installing a Role:
ansible-galaxy install [username].[role_name]
Creating and Sharing Roles
You can also create your own roles and share them on Ansible Galaxy:
1. Create a role:
ansible-galaxy init [my_new_role]
After customizing the role, share it on Ansible Galaxy by uploading it to a public GitHub repository and importing it to the Galaxy website.