From Zero to One: A Practical Guide to Cloud Migration and Automated Deployment with Ansible
This article details a real‑world cloud migration journey using Tencent Cloud services, explains one‑click provisioning of components like Zookeeper and Redis, outlines data migration strategies, and demonstrates how to automate build and deployment pipelines with Ansible playbooks and scripts.
In this post the author shares the experience of migrating a business system from a shared group environment to an independent cloud setup on Tencent Cloud, describing the motivations, challenges, and the overall architecture of the migration.
The article first lists the essential cloud services required for a complete system—DNS, CDN, access layer, middleware, storage, APM—and shows how Tencent Cloud provides one‑click deployment for components such as Zookeeper clusters and Redis sharded clusters, reducing manual configuration and error risk.
Cost‑saving measures are discussed, including consolidating low‑spec services on a single VM, sharing front‑end projects on the same host with CDN acceleration, and optimizing APM data collection by limiting sampling and centralizing monitoring.
Data migration is covered in detail: full‑plus‑incremental database migration using Tencent Cloud's data migration service; configuration center migration with the open‑source zkcopy tool (example command shown); Redis migration via an AOP‑based dual‑write approach with sample Java AOP code; and MQ migration using a gray‑release strategy to ensure a smooth cut‑over.
The author then introduces Ansible as the automation tool of choice, highlighting its SSH‑based, agent‑less operation, rich core modules, and playbook‑driven workflow. Key advantages such as simplicity, extensibility, and built‑in modules for shell, copy, file, fetch, command, and cron are enumerated.
Three essential files are presented:
production-hosts.yaml – the inventory defining build machines and service hosts.
java-build.yaml – the build playbook that pulls source code, grants execution permissions, runs the build script, archives the resulting JAR, and fetches artifacts back to the Ansible control node.
java-deploy.yaml – the deployment playbook that pushes the JAR and deployment script to target servers, starts the service, and performs health checks via HTTP.
java -jar target/zkcopy.jar --source server:port/path --target server:port/path @Slf4j
@Aspect
@Component
public class AopRedisReadWriteAspect {
@Resource
private RebateNewCacheClient rebateNewCacheClient;
@Around(value = "execution(* com.xxx.RedisCacheClient.setex(String,int,String)) && args(key,expire,value)")
public Object setEx(ProceedingJoinPoint joinPoint, String key, int expire, String value) {
rebateNewCacheClient.setEx(key, expire, value);
return invokeOrigin(joinPoint);
}
private Object invokeOrigin(ProceedingJoinPoint joinPoint) {
try { return joinPoint.proceed(); } catch (Throwable t) { /* log */ }
return null;
}
}Running the playbooks is straightforward:
ansible-playbook -i production-hosts.yaml java-build.yaml # build on the build machine
ansible-playbook -i production-hosts.yaml java-deploy.yaml # deploy to production serversThe author concludes that using Ansible’s core modules enables a clear, repeatable deployment pipeline, while acknowledging that additional concerns such as rollback are beyond the scope of this article.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.