Operations 4 min read

Ansible Basics: Copy, Command, and Backup Operations with Practical Examples

This article introduces Ansible’s agent‑less architecture, explains its reliance on SSH and Python, and demonstrates common copy, command, and backup tasks through clear command‑line examples for remote hosts.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Ansible Basics: Copy, Command, and Backup Operations with Practical Examples

Ansible is built on Paramiko and provides a modular, agent‑less framework for batch deployment, configuration, and command execution by communicating over SSH; it is developed in Python and has been acquired by Red Hat.

[root@mha ~]# ansible web -m copy -a 'src=/root/a.sh dest=/tmp/'

This command copies the file a.sh from the control node to /tmp/ on all hosts in the web inventory group. [root@mha ~]# ansible web -m command -a 'ls /tmp/' Runs the ls /tmp/ command on the same hosts, showing the copied file.

[root@mha ~]# ansible web -m copy -a 'src=/root/file.txt  owner=root group=root dest=/tmp/file.txt  backup=yes'

Copies file.txt to /tmp/ with ownership set to root and enables backup of the destination file.

[root@mha ansible]# ansible web -m copy -a 'src=/etc/ansible/roles dest=/tmp/ backup=yes'

Copies the entire /etc/ansible/roles directory to /tmp/ on each target, creating backups; the output shows a CHANGED status with details of the source and destination paths for each host. [root@mha ansible]# ansible web -m shell -a 'ls -lrth /tmp/' Executes a shell command to list the contents of /tmp/ in long format, confirming that the files were transferred successfully.

----------------------end---------------------

Recommended reading:

1. Ansible Detailed User Module

2. K8s Pod Resource Manifest Writing

3. Prometheus Service Discovery

4. Prometheus Monitoring Implementation – Practical Guide

5. Conditional Syntax in Playbooks

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AutomationConfiguration ManagementDevOpsAnsible
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.