🔗Associated content material
You could find repo associated in:
🐱🏍GitHub
You may join with me in:
Resume 🧾
- 📜 Nothing to renew,it is easy.
Introduction
🤖 Ansible is an open-source automation device that simplifies complicated duties, accelerates workflows, and will increase productiveness. It permits customers to automate configuration administration, utility deployment, and job automation.
🔑 Ansible is agentless, which suggests it doesn’t require any software program or agent to be put in on the distant machines that it manages. As a substitute, it makes use of SSH or WinRM to connect with distant hosts.
📝 Ansible makes use of a easy and human-readable syntax referred to as YAML (But One other Markup Language), which makes it straightforward for customers to create and handle their automation scripts. Ansible playbooks are written in YAML and are a set of directions that inform Ansible what to do.
Makes use of
💻 Ansible helps a variety of platforms, together with Linux, Unix, macOS, and Home windows. It additionally integrates with quite a lot of cloud suppliers reminiscent of AWS, Azure, and Google Cloud Platform.
♻️ Ansible’s idempotent nature permits it to be run a number of instances with out altering the top consequence. This makes it straightforward to check and re-run automation scripts with out worrying about undesired adjustments or unintended effects.
🛠️ Ansible is very extensible and will be built-in with different instruments and companies. For instance, it may be built-in with Git, Jenkins, and plenty of different DevOps instruments to create a strong and streamlined automation pipeline.
Examples
Listed below are some examples of what Ansible can do:
- Automate the set up and configuration of software program packages on a number of servers
- Deploy net purposes and companies to a number of servers concurrently
- Handle community gadgets reminiscent of switches and routers
Provision digital machines in a cloud atmosphere - Configure and handle container orchestration platforms like Kubernetes
General, Ansible is a strong and versatile automation device that may assist organizations automate their IT workflows and enhance their effectivity. Whether or not you are a developer, system administrator, or IT skilled, Ansible may help you streamline your automation processes and obtain your automation objectives.
Sensible case
As an instance you might have an online utility that you simply need to deploy to a number of servers concurrently. You need to automate the method of deploying the applying to the servers and be sure that the servers are configured appropriately earlier than the deployment. You additionally need to be certain that the applying is deployed persistently throughout all servers, even when you’ll want to re-run the deployment course of.
To perform this, you should utilize Ansible to put in writing a playbook that automates the deployment and configuration course of. This is an instance of what the playbook would possibly appear to be:
---
- identify: Deploy net utility
hosts: webservers
develop into: sure
vars:
app_name: myapp
app_version: 1.0.0
app_port: 8080
duties:
- identify: Set up dependencies
apt:
identify: ["git", "python3-pip", "nginx"]
state: current
- identify: Clone repository
git:
repo: https://github.com/myusername/myapp.git
dest: /decide/{{ app_name }}-{{ app_version }}
- identify: Set up Python dependencies
pip:
necessities: /decide/{{ app_name }}-{{ app_version }}/necessities.txt
- identify: Configure Nginx
template:
src: nginx.conf.j2
dest: /and so forth/nginx/sites-available/{{ app_name }}
notify:
- Reload Nginx
- identify: Allow website
file:
src: /and so forth/nginx/sites-available/{{ app_name }}
dest: /and so forth/nginx/sites-enabled/{{ app_name }}
state: hyperlink
notify:
- Reload Nginx
- identify: Begin utility service
systemd:
identify: {{ app_name }}
state: began
enabled: sure
daemon_reload: sure
handlers:
- identify: Reload Nginx
systemd:
identify: nginx
state: reloaded
...
On this instance, the playbook specifies that it is going to be run on a gaggle of hosts referred to as “webservers”. It then defines a set of duties that shall be executed on every of those hosts.
The primary job installs the required dependencies on the hosts utilizing the apt module. The following job clones the applying’s Git repository to the hosts utilizing the git module. The third job installs the Python dependencies of the applying utilizing the pip module.
The fourth job configures Nginx by producing a template file primarily based on a Jinja2 template and copying it to the suitable location utilizing the template module. It then notifies the Reload Nginx handler, which is outlined later within the playbook.
The fifth job permits the Nginx website by making a symbolic hyperlink to the positioning’s configuration file utilizing the file module. It additionally notifies the Reload Nginx handler.
The sixth and ultimate job begins the applying service utilizing the systemd module. It additionally ensures that the service is enabled to start out robotically on boot and notifies daemon_reload to reload the systemd configuration.
The playbook additionally defines a handler referred to as Reload Nginx, which reloads the Nginx configuration utilizing the systemd module.
By working this playbook with Ansible, you’ll be able to automate the deployment and configuration of your net utility throughout a number of servers with ease.