This project outlines a comprehensive approach to setting up a CentOS virtual machine using Vagrant, establishing secure SSH connections, and leveraging Ansible for automated configuration management and deployment.
This structured approach provides a robust framework for managing and deploying CentOS VMs and configurations using modern DevOps tools like Vagrant, Docker, and Ansible.
The project is divided into several key stages:
Initialize and launch a CentOS virtual machine using a command:
vagrant up
vagrant build my virtual machine centos 7 with configuration of my IP and add my ssh key
We use private Key for connection :
ssh -i testkey root@192.168.57.200
If you get some issue try to clean your "known_hosts"
Debug:
ssh -i testkey root@192.168.57.200 -v
Automatically start Docker Desktop using PowerShell to facilitate the Ansible environment setup:
powershell -Command "Start-Process 'C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe'"
Build a Docker image pre-configured with Ansible, including necessary SSH keys and playbooks, to streamline the deployment process:
docker build -t testcentos .
Run the Ansible Docker container and verify connectivity with the VM through an Ansible ping command:
docker run -it testcentos
Check if we can call the VM inside the container :
ansible -i /tmp/inventory vms -m ping
or
ansible-playbook -i /tmp/inventory /tmp/playbook.yml
Mount a local project directory into the Docker container, enabling access to playbooks and inventory files
Run with volume project:
docker run -v C:/tmp/Lab_VM_Ansible_Automation/ansible-project:/tmp -it testcentos
Run specific Ansible playbooks within the container to install and configure software on the VM, with options for detailed debugging output:
Run playbook install_docker.yml :
ansible-playbook -i /tmp/inventory/development /tmp/playbooks/install_docker.yml
Run playbook uninstall_docker.yml :
ansible-playbook -i /tmp/inventory/development /tmp/playbooks/uninstall_docker.yml
Mode Debug :
ansible-playbook -i /tmp/inventory/development -vvv /tmp/playbooks/install_docker.yml