Skip to content
Mohamed#Dridi edited this page Apr 9, 2023 · 5 revisions

Welcome to the Ansible_101 wiki!

The Ansible_101 wiki provides a step-by-step guide on how to install Ansible, configure SSH plugin, create an inventory file, test connectivity between master and target machines, and create a playbook to automate tasks. It also includes a section on adding root privileges to the user and how to use the wiki.

Installation

Install Ansible: sudo apt install ansible

Install sshpass: sudo apt-get install sshpass

sshpass is a tool used to automate SSH password authentication in a non-interactive way. In the context of Ansible, sshpass can be used as a plugin to enable password authentication for SSH connections in the ansible_connection parameter of the inventory file or playbooks.

Configuration

Add domain names to the management machine by editing the hosts file: nano /etc/hosts and adding 192.168.1.100 myserver.example.com Find your domain name by running hostname -d Create an inventory file: nano inventory.yaml with the following content:

[server]
192.168.182.134 ansible_user=admin1 ansible_password=root ansible_python_interpreter=/usr/bin/python3

Note: If your target machine uses Python 3, add the following parameter to the inventory file: ansible_python_interpreter=/usr/bin/python3

Testing

Test the connection to all machines in the inventory file: ansible all -i inventory.yaml -m ping Create a playbook to test connectivity: nano test-connectivity.yml Run the playbook:

ansible-playbook test-connectivity.yml -i inventory.yaml

Privilege escalation

Grant root privileges to the user running Ansible by editing the sudoers file: sudo nano /etc/sudoers Add the following line to the file: username ALL=(ALL) NOPASSWD: ALL Replace username with the name of the user you are using with Ansible. Save the file and exit the editor before running your playbook again.

Clone this wiki locally