Ansible Role CI for Ceph using Molecule, OpenStack, Ceph-Ansible and GitHub Actions — Part 2

Kevin Coakley
3 min readMay 4, 2020

--

Part 2: Install Ceph on the servers using ceph-ansible

Part 1: Configuring Molecule OpenStack Driver
Part 3: Automatically run the Molecule test using GitHub Actions and OpenStack

I described in part 1 how to use the Molecule OpenStack driver to create 1 mon server and 3 osd servers in OpenStack for a Ceph install by updating Molecule’s create.yml and destroy.yml files.

In this part I will describe how to install Ceph using ceph-ansible during the prepare phase of the Molecule test run.

First, I will update molecule.yml to use the gilt dependency module to clone ceph-ansible repository.

dependency:
name: gilt

I updated the platforms section of molecule.yml to include the Ansible inventory groups that each server will belong to according to the role each server will provide to the Ceph cluster.

platforms:
- name: "mon-1"
image: CentOS 7.6 x86_64
flavor: m1.medium
groups:
- mons
- mgrs
- name: "osd-1"
image: CentOS 7.6 x86_64
flavor: m1.medium
groups:
- osds
- name: "osd-2"
image: CentOS 7.6 x86_64
flavor: m1.medium
groups:
- osds
- name: "osd-3"
image: CentOS 7.6 x86_64
flavor: m1.medium
groups:
- osds

Ceph-ansible requires specific settings in the ansible.cfg file in order to run. I will update the provisioner settings in molecule.yml to use the ansible.cfg file provided by ceph-ansible git repository. Finally, I will set all of the group_vars needed to configure a running Ceph cluster. I combined the general, mon, mgr and osd group_vars into a single group_vars called all for simplicity. Refer to the ceph-ansible documentation if you have any questions about specific ceph-ansible group_vars settings.

provisioner:
name: ansible
log: false
env:
ANSIBLE_CONFIG: $MOLECULE_EPHEMERAL_DIRECTORY/ceph-ansible/ansible.cfg
inventory:
group_vars:
all:
configure_firewall: false
ntp_service_enabled: false
ceph_origin: repository
ceph_repository: community
ceph_stable_release: nautilus
monitor_interface: eth0
radosgw_interface: eth0
public_network: 192.168.0.0/24
cluster_network: 192.168.0.0/24
osd_objectstore: bluestore
dashboard_enabled: false
devices:
- /dev/sdb

Next, I created the gilt.yml file in order to clone the ceph-ansible repository at the v4.0.20 tag in the $MOLECULE_EPHEMERAL_DIRECTORY/ceph-ansible/ directory. The $MOLECULE_EPHEMERAL_DIRECTORY directory is a temp directory created by Molecule that lasts for the duration of the Molecule test run.

---
- git: https://github.com/ceph/ceph-ansible.git
version: v4.0.20
dst: $MOLECULE_EPHEMERAL_DIRECTORY/ceph-ansible/

Finally, I will update the prepare.yml file to install and test Ceph using ceph-ansible. Ceph-ansible uses multiple roles in order to install and configure Ceph. I will just need to import the site.yml.sample playbook stored in the root of the gilt cloned ceph-ansible git repository. Molecule also sets the path of $MOLECULE_EPHEMERAL_DIRECTORY as an enviroment variable so it can be referred to in Ansible playbooks and roles by: {{ lookup(‘env’, ‘MOLECULE_EPHEMERAL_DIRECTORY’) }} . Then I run a test after ceph-ansible has been completed to verify that the Ceph cluster is in a healthy state before Molecule proceeds to running the converge.yml step.

---
- name: include the ceph-ansible playbook
import_playbook: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ceph-ansible/site.yml.sample"

- name: Converge
hosts: all
become: true

vars:
cluster: ceph
mon_group_name: mons

post_tasks:
- name: Give Ceph time to work
pause: seconds=5

- name: Check ceph health
command: "ceph --connect-timeout 5 --cluster {{ cluster }} health"
changed_when: false
delegate_to: "{{ groups[mon_group_name][0] }}"
register: ceph_health
until: ceph_health is succeeded
run_once: true
failed_when: "'HEALTH_OK' not in ceph_health.stdout"

Now you should have a working Ceph cluster that you can use to test your Ceph Ansible roles by completing the converge.yml and verify.yml files.

In the last part I will describe how to automatically run the Molecule test using GitHub Actions when there is a new commit.

The full repository of all of the code is at https://github.com/kevincoakley/ansible-role-ceph-pools

--

--