First things first, we kickstarted our infrastructure setup by using shell scripts to install Ansible on an EC2 instance. Additionally, we fine-tuned our automation process by configuring automate_ssh_pub.sh. This script ensured that our public key was copied to all other instances, and it seamlessly appended the public key to the authorized_keys files. This step was crucial to automate and for secure and efficient communication between our Ansible control node and the managed servers.
- We set up two web servers, with the same website configuration. Ansible allowed us to define these configurations declaratively.
- Our web servers were ready to handle incoming
HTTPrequests, thanks to Ansible’s streamlined management.
- For our data storage needs, we deployed two
MySQLdatabases. These databases were essential for our applications to store and retrieve data efficiently. - Ansible took care of configuring
MySQL, setting up users, and securing the databases.
- Time synchronization across our infrastructure was critical. To achieve this, we set up an
NTPserver on our Ansible control node. - Additionally, we configured
NTPclients on all our web servers and databases. This ensured that they synced their clocks with our centralNTPserver. - Accurate timekeeping is essential for various tasks, including logging, security certificates, and coordinated system operations.
apt: It allows you to install, update, or remove packages using the system’s package manager.replace: You can use it to search for a specific pattern (e.g., a string or regular expression) and replace it with another value, and withreplace: ''we deleted this pattern.lineinfile: The lineinfile module allows you to manage lines within a file.service: The service module controls system services (starting, stopping, enabling, or disabling services).shell: The shell module runs shell commands directly on the target system.get_url: The get_url module downloads files from a URL and saves them locally.unarchive: The unarchive module extracts compressed archives (e.g., .tar.gz, .zip) on the target system.copy: The copy module copies files or directories from the control machine to the target system.file: The file module manages files and directories, Theabsentstate ensures that a file or directory does not exist.mysql_userandmysql_db: These modules manage MySQL users and databases.notify: The notify module triggers handlers (tasks defined elsewhere in the playbook) when notified.
- To keep our playbook organized and modular, we configured Ansible roles.
- Each role encapsulated a specific functionality (e.g., web server setup, database configuration,
NTPmanagement). - Roles allowed us to reuse code, maintain consistency, and simplify playbook maintenance.
- This feature helps us to write our project in a single simple playbook.yml file, This playbook orchestrated the entire deployment process.