-
Notifications
You must be signed in to change notification settings - Fork 685
Usage of Molecule and Ansible for development
We use Ansible heavily in SecureDrop project. Except the actual installation process, we use Molecule along with ansible for the other steps.
All the available molecule scenarios can be found at ./molecule/
directory.
- builder-xenial
- builder-focal
- testinfra
- vagrant-packager
- fetch-tor-packages
- libvirt-staging-xenial
- libvirt-staging-focal
- qubes-staging-focal
- qubes-staging-xenial
- upgrade
- virtualbox-staging-xenial
These 2 scenarios build the debian packages for the SecureDrop
server code and related packages.
For the following, we will examine the builder-focal
scenario.
Let us dig into the files in the scenario.
- ansible-override-vars.yml
- The file contains two variables which are used in conditions to mark that we are building for Focal. These are used inside of the actual package building roles.
- aptpreferences.conf
- Apt file
- create.yml
- This creates all the containers defined in the molecule.yml file.
- destroy.yml
- Destroys the containers created in the create step
- Dockerfile
- Dockerfile for the builder container image, this needs to pushed to the container repository
- image_hash
- Hash of the container image
- Makefile
- The make file
- molecule.yml
- Main file which defines all configurations, from where to find the Ansible roles, and what all steps should be takes for this scenario.
- playbook.yml
- After the containers are running, this runs the various roles to build the actual packages. It also does the initial package testing. Check the various roles in "Build SecureDrop application Debian package from local repository." task to find which package gets build via which container.
- push.sh
- To push the container image.
- Using python requests package, it first downloads the ossec source tarball.
- We use our own systemd service (two different files) for both server and agent on Focal. On Xenial we are still using the old
sysv
script. - Remember that the same role is being used to build both agent and server, configuration changes dynamically based on conditions.
- 2 containers started for
Xenial
andFocal
(molecule/fetch-tor-packages/molecule.yml) - Then the
playbook.yml
sets up Tor Apt repository - Download the Tor debs via
apt-get download
command - Sync them back into host machine
Path: install_files/ansible-base/roles/build-securedrop-app-code-deb-pkg/
All steps are in the tasks/main.yml
.
Path; install_files/ansible-base/roles/build-ossec-deb-pkg
- name: Copy our systemd based service file for ossec-server
copy:
src: ossec.service
dest: "{{ ossec_build_dir }}/etc/systemd/system/ossec.service"
when:
- ansible_host.endswith("-sd-generic-ossec-server")
- ansible_distribution_release == "focal"
- name: Copy our systemd based service file for ossec-agent
copy:
src: ossec-agent.service
dest: "{{ ossec_build_dir }}/etc/systemd/system/ossec.service"
when:
- ansible_host.endswith("-sd-generic-ossec-agent")
- ansible_distribution_release == "focal"
Path: install_files/ansible-base/roles/build-generic-pkg/tasks/main.yml
- role: build-generic-pkg
tags: securedrop-ossec-server
package_name: securedrop-ossec-server
when: ansible_host.endswith("-sd-generic-ossec-server2") or ansible_host == "localhost"
- role: build-generic-pkg
tags: securedrop-ossec-agent
package_name: securedrop-ossec-agent
when: ansible_host.endswith("-sd-generic-ossec-agent2") or ansible_host == "localhost"
The same build-generic-pkg
also builds next 3 packages, securedrop-keyring, securedrop-grsec, securedrop-config.
As part of the task: Give dpkg verify container access to debs
we copy over the fresh debian packages into the tester container. This is in the playbook.yml
file.
This is defined in the verifier
section of the molecule.yml
file. The testinfra runs ../builder-xenial/tests/
tests for the same.
This is being done via fetch-tor-packages
scenario. The following things happen in this:
This scenario assumes that you already built the packages for the Focal
and they are available in ./build/focal/
directory.
As a first step, create.yml
creates two vms based on the configuration from molecule.yml
file.
For the converge, we should look at ./install_files/ansible-base/securedrop-staging.yml
playbook.
When running against a staging or production host, the following playbooks will be applied to the host (generated with ansible-playbook-grapher)