Step-by-Step Guide to Installing and Configuring Ansible on Linux
This article provides a complete walkthrough for installing Ansible via yum, disabling host key checking, setting up an inventory file, testing basic commands, generating SSH keys, creating a playbook to distribute keys, and verifying password‑less SSH access on remote servers.
1. Install Ansible
Run the following command to install Ansible on a RHEL/CentOS system:
yum install ansible
2. Modify the configuration
Edit /etc/ansible/ansible.cfg and change the line
#host_key_checking = False
to
host_key_checking = False
This disables the SSH host‑key verification prompt on first connection.
3. Configure the hosts inventory
Add a group called [test] with the target servers and login credentials:
[test]
192.168.20.26 ansible_ssh_user=root ansible_ssh_pass='xxxxxx'
192.168.20.53 ansible_ssh_user=root ansible_ssh_pass='xxxxxx'4. Test Ansible connectivity
Execute a simple module to check the remote host:
ansible test -m shell -a 'uptime'
5. Generate SSH key pair on the control node
Run:
ssh-keygen
Follow the prompts to create id_rsa and id_rsa.pub .
6. Distribute the public key with a playbook
Create key_pub.yml :
- hosts: test
remote_user: root
tasks:
- name: copy ssh key
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
state: present
mode: 06007. Run the playbook
ansible-playbook key_pub.yml
This copies the public key to the remote hosts, enabling password‑less SSH.
8. Verify password‑less login
Test the SSH connection:
ssh 192.168.20.26
If the login succeeds without a password prompt, the setup is complete.
--- End of guide ---
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.