Abstract
Enable repeatable deployments of etcd with Ansible.
Automate the etcd deployment with Ansible#
The lack of a cloud service or an appropriate Terraform provider leaves us with 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 Ansible. But Ansible is the simplest to implement and most familiar to the author, so other configuration management tools are not used here.
The Ansible code we’ll use for this purpose is located in the ansible-etcd GitHub repository.
Make it repeatable#
In a previous post we did a quick and dirty deployment of etcd to the control plane node. Today, we’ll make that a repeatable and idempotent operation.
To do this, we’ll create a new Ansible role, then add a task and a handler to the role and a playbook to call the role from.
Initialize the role.
mkdir -pv roles cd roles ansible-galaxy role init etcd
Next, add a handler for the install task.
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
Add the install task.
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
Add the playbook.
site.yml#--- - name: Install etcd hosts: etcd roles: - role: etcd tags: - etcd
To use them, you will run the
ansible-playbook
command as shown below.ansible-playbook site.yml