Spent some time tinkering at home on Saturday; all processes below have been gradually experimented and implemented;
This article is based on practical operations and organized with ChatGPT, aiming to help readers quickly master the practical methods of Ansible in a local environment simulating multi-hosts with Docker.
Table of Contents
-
Market Share and Value of Ansible
-
Getting Started with Ansible and Installation Debugging on Windows/WSL
-
Multi-Host Simulation with Ansible (Docker Solution)
-
Debugging Docker Containers and Bulk Tool Installation
-
Summary and Extension Suggestions
1. Market Share and Value of Ansible
Question
Is Ansible’s market share high? Is it worth learning? What problems does it mainly solve?
Market Data (2025)
-
Ansible: Market share 31.45%, ranking second among configuration management tools, second only to Terraform, higher than Puppet and Chef.
-
Red Hat Ansible Automation Platform: Market share 16.8%, still one of the mainstream solutions for enterprise automation.
Learning Value
-
Gentle learning curve, Agentless (no need to install agents on clients)
-
Deep integration with Python, strong script extension capabilities
-
Widely used in DevOps, cloud automation, network device management
-
Stable demand for Ansible talent in medium to large enterprises
Main Applicable Scenarios
-
Configuration management (unifying server environments)
-
Application deployment (rolling updates, blue-green releases)
-
IaC (Infrastructure as Code)
-
Task automation (batch operations, monitoring, backups)
-
CI/CD process integration
-
Network automation (Cisco/Juniper and other devices)
-
Consistency across development, testing, and production environments
💡 Suggestions
-
Use AI to assist in generating learning paths and practice hands-on with official documentation
-
Start with the smallest Playbook (e.g., disk check) and then expand to multiple nodes
-
Practice repeatedly in local + test server environments to improve portability
2. Getting Started with Ansible and Installation Debugging on Windows/WSL
Quick Start Example: Disk Space Check
<span>inventory.ini</span>
[local]
localhost ansible_connection=local
<span>playbook.yml</span>
---
- name: Check Disk Space
hosts: local
tasks:
- name: Get disk usage
ansible.builtin.shell: df -h
register: disk_output
- name: Display disk report
ansible.builtin.debug:
msg: "{{ disk_output.stdout }}"
Run Command
ansible-playbook -i inventory.ini playbook.yml
Common Issues in Windows/WSL Environment Debugging
-
Native installation on Windows may encounter Blocking IO errors
-
<span>apt</span>command may be unavailable (missing WSL configuration)
Solutions
# Install WSL and Ubuntu
wsl --install -d Ubuntu
# Update system and install Ansible
sudo apt update && sudo apt upgrade -y
sudo apt install ansible -y
Experience Tips
-
Avoid executing control node tasks directly on Windows; it is recommended to use WSL/Linux
-
If Docker Desktop is installed, check WSL integration in the top right corner gear → Resources for easier visual management of containers
3. Multi-Host Simulation with Ansible (Docker Solution)
Dockerfile (Ubuntu with SSH)
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y openssh-server sudo && \
mkdir /var/run/sshd && \
useradd -m -s /bin/bash ansibleuser && \
echo "ansibleuser:password" | chpasswd && \
echo "ansibleuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
ssh-keygen -A
CMD ["/usr/sbin/sshd", "-D"]
Build and Start Multiple Containers
docker build -t ansible-ubuntu .
for i in {1..10}; do
PORT=$((2200 + i))
docker run -d -p $PORT:22 --name host$i ansible-ubuntu
done
Inventory Configuration (multi-hosts.ini)
[simulate_hosts]
host1 ansible_host=127.0.0.1 ansible_port=2201 ansible_user=ansibleuser ansible_password=password
# host2...host10 incrementing ports
Ansible Configuration Optimization<span>~/.ansible.cfg</span>
[defaults]
host_key_checking = False
timeout = 30
Test Connectivity
ansible -i multi-hosts.ini simulate_hosts -m ping
4. Debugging Docker Containers and Bulk Tool Installation
Playbook for Bulk Installation of Common Tools
---
- name: Install Common Tools on Simulate Hosts
hosts: simulate_hosts
become: yes
tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
- name: Install common tools
ansible.builtin.apt:
name:
- net-tools
- iproute2
- iputils-ping
- htop
- vim
- tcpdump
- curl
- wget
state: present
- name: Verify installation
ansible.builtin.shell: htop -V
register: htop_output
ignore_errors: yes
- name: Display result
ansible.builtin.debug:
msg: "{{ htop_output.stdout | default('htop not installed') }}"
Run Command
ansible-playbook -i multi-hosts.ini install_tools.yml --ask-become-pass
Note: The Ubuntu image in Docker is a minimal version, and some services that depend on systemd cannot run.
5. Summary and Extension Suggestions
Ansible Practical Experience
-
Quickly set up a testing environment using WSL + Docker
-
Add
<span>-vvv</span>during debugging to view detailed logs -
Separate management of Inventory and Playbook
Docker Usage Experience
-
Minimal images require manual completion of tools
-
To keep containers running long-term:
CMD ["tail", "-f", "/dev/null"]
# or
sshd -D
Common Issues
-
YAML indentation errors causing Playbook execution failures
-
SSH fingerprint check blocking the first connection (need to disable host_key_checking)
-
When systemd is missing, lightweight alternatives need to be used
Extension Directions
-
Use Ansible to manage Docker container lifecycle
-
Integrate automated build and deployment pipelines (CI/CD)
-
Use Molecule for automated testing of Playbooks