English translation
System Administration and Automated Deployment with Ansible
AI Article Decision Snapshot
Turn the lesson into workflow, model, budget, and security checks before choosing tools.
Use this quick snapshot before leaving the article. It keeps the next search tied to practical AI software, model/API, cost, privacy, and implementation questions.
Workflow fit
Identify the real job behind the article: coding, research, document review, support, analytics, content, or internal automation.
Model or tool decision
Decide whether the next step is a software shortlist, an AI tool comparison, an API platform choice, or a model benchmark.
Budget and usage signal
Estimate seats, API calls, prompt volume, retries, review time, and fallback work before assuming the workflow is cheap.
Security and privacy review
Check whether source code, customer data, private documents, prompts, logs, or embeddings will enter the AI workflow.
In this tutorial, we will delve into common use cases for system administration and automated deployment using Ansible. As mentioned in the previous article, Ansible Galaxy enables us to share and reuse roles—providing a foundational layer for our automation workflows. Here, we’ll build concrete, practical examples based on these reusable roles to help you better understand real-world Ansible applications.
Case 1: Automated Deployment of a Web Server
In modern cloud environments, rapidly deploying and managing web servers is a critical operational task. Below is an example of using Ansible to automatically deploy an Nginx web server.
1. Prerequisites
First, ensure Ansible is installed and that your target servers are accessible via SSH. Next, create a playbook file—for example, deploy_nginx.yml:
---
- name: Deploy Nginx on Web Server
hosts: webservers
become: yes
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install Nginx
apt:
name: nginx
state: present
- name: Start Nginx Service
service:
name: nginx
state: started
enabled: yes
2. Running the Playbook
Ensure your inventory file defines a host group named webservers, then execute the playbook with:
ansible-playbook -i inventory deploy_nginx.yml
This example demonstrates how straightforward it is to manage and automate software installation with Ansible. Upon completion, Nginx will be installed on the target server, started, and configured to launch automatically at boot.
Case 2: User and Permission Management
Managing users and permissions is another essential operational task—especially in multi-user environments. Below is an example of using Ansible to manage users.
1. Creating the Playbook
Create a playbook named manage_users.yml:
---
- name: Manage Users
hosts: all
become: yes
tasks:
- name: Ensure user 'deployer' exists
user:
name: deployer
state: present
shell: /bin/bash
groups: sudo
- name: Set password for user 'deployer'
user:
name: deployer
password: "$6$rounds=656000$saltsal$hashedpassword" # Generate a secure password using `mkpasswd`
2. Running the Playbook
As before, verify your inventory file includes the relevant hosts, then run:
ansible-playbook -i inventory manage_users.yml
This playbook ensures the user deployer exists and is granted sudo privileges. You can extend it further to manage additional users or fine-grained permission policies as needed.
Case 3: Automated Application Deployment
In microservices-based architectures, automating application deployment is key to improving development velocity and operational reliability. Below is an example deploying a simple Flask application.
1. Flask Application Playbook
Create deploy_flask_app.yml to deploy your Flask app:
---
- name: Deploy Flask Application
hosts: webservers
become: yes
tasks:
- name: Install dependencies
apt:
name:
- python3
- python3-pip
state: present
- name: Install Flask
pip:
name: Flask
- name: Copy application code
copy:
src: /path/to/your/flask_app/
dest: /var/www/flask_app/
- name: Create supervisor config
copy:
dest: /etc/supervisor/conf.d/flask_app.conf
content: |
[program:flask_app]
command=python3 /var/www/flask_app/app.py
autostart=true
autorestart=true
stderr_logfile=/var/log/flask_app.err.log
stdout_logfile=/var/log/flask_app.out.log
- name: Start supervisor service
service:
name: supervisor
state: started
enabled: yes
2. Running the Playbook
Execute the playbook with:
ansible-playbook -i inventory deploy_flask_app.yml
This workflow automatically installs Python, Flask, and its dependencies; copies your application code to the target server; configures Supervisor to manage the application process; and starts the Supervisor service—ensuring your Flask app runs persistently and restarts automatically if it crashes.
Summary
In this tutorial, we explored several common Ansible use cases for system administration and automated deployment. Through these hands-on examples, we demonstrated how Ansible simplifies web server provisioning, user and permission management, and application deployment. In the next tutorial, we’ll extend our coverage to automated configuration of network devices—stay tuned!
We hope these examples help you leverage Ansible effectively for robust, scalable system management!
Apply This Lesson
Turn this article into AI software, model, API, and security decisions.
English Article FAQ
Use this article as evidence before choosing AI tools
How should I use this AI Tutorials article?
Use it as the implementation or learning layer, then connect the idea to AI software buyer guides, tool comparisons, benchmarks, API choices, and security checks before making a production decision.
Is this English article different from the Chinese original?
The English edition is localized for global AI readers while preserving the original diagrams, screenshots, prompts, code examples, and source context from the Chinese article.
What should I read after System Administration and Automated Deployment with Ansible?
Continue with AI Software Buyer Guides, AI Tools Workbench, Best AI Coding Agents, AI Model Benchmarks, OpenAI vs Anthropic API, or LLM Security Tools depending on the decision you need to make.
Can this article alone choose an AI product or model?
No. Treat the article as evidence and context, then validate fit with pricing, privacy requirements, integration effort, benchmark results, workflow tests, and fallback planning.
Continue