---
abstract: Enable repeatable deployments of etcd with Ansible.
author: Xander Harris
blogpost: true
category: Preparation
date: 2025-06-24
tags: etcd, prep
title: Automate the etcd deployment with Ansible
---

The lack of a cloud service or an appropriate Terraform provider
leaves us with {term}`Ansible` for configuration management.
Configuration management can be done with many other tools, even
simple bash and ssh which shares the advantage of being agent-less
with {term}`Ansible`. But {term}`Ansible` is the simplest
to implement and most familiar to the author, so other configuration
management tools are not used here.

The {term}`Ansible` code we'll use for this purpose is located in the
[ansible-etcd](https://github.com/edwardtheharris/ansible-etcd) GitHub
repository.

## Make it repeatable

In a previous post we did a quick and dirty deployment of {term}`etcd`
to the control plane node. Today, we'll make that a repeatable
and idempotent operation.

To do this, we'll create a new {term}`Ansible` role, then add
a task and a handler to the role and a playbook to call the role from.

1. Initialize the role.

   ```{code-block} shell
   mkdir -pv roles
   cd roles
   ansible-galaxy role init etcd
   ```

2. Next, add a handler for the install task.

   ```{code-block} yaml
   :caption: roles/etcd/handlers/main.yml

   # SPDX-License-Identifier: MIT-0
   ---
   - name: Start etcd
     ansible.builtin.service:
       name: etcd
       state: restarted
       enabled: true
     become: true
   # handlers file for etcd
   ```

3. Add the install task.

   ```{code-block} yaml
   :caption: roles/etcd/tasks/main.yml

   # SPDX-License-Identifier: MIT-0
   ---
   - name: Install etcd
     community.general.pacman:
       name: etcd-bin
       executable: yay
       state: present
     notify: Start etcd
   # tasks file for etcd
   ```

4. Add the playbook.

   ```{code-block} yaml
   :caption: site.yml

   ---
   - name: Install etcd
     hosts: etcd
     roles:
       - role: etcd
         tags:
           - etcd
   ```

5. To use them, you will run the `ansible-playbook` command as shown below.

   ```{code-block} shell
   ansible-playbook site.yml
   ```
