Skip to content

Commit

Permalink
feat: cdnsd role (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Mar 13, 2024
1 parent 3c3ee23 commit f6f2e96
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
50 changes: 50 additions & 0 deletions roles/cdnsd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cdnsd
=========

This role deploys a cDNSd instance.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should
be mentioned here. For instance, if the role uses the EC2 module, it may be a
good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including
any variables that are in defaults/main.yml, vars/main.yml, and any variables
that can/should be set via parameters to the role. Any variables that are read
from other roles and/or the global scope (ie. hostvars, group vars, etc.)
should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in
regards to parameters that may need to be set for other roles, or variables
that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables
passed in as parameters) is always nice for users too:

```yaml
- hosts: servers
tasks:
- include_role:
name: blinklabs.cardano.cdnsd
```
License
-------
Apache 2.0
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
35 changes: 35 additions & 0 deletions roles/cdnsd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# Install method
cdnsd_install_method: 'docker'

# cDNSd version
cdnsd_version: '0.11.1'

# Base host directory for node data
cardano_node_dir: /opt/cardano

# DB directory for host/container
cdnsd_db_dir: '{{ cardano_node_dir }}/cdnsd'
cdnsd_db_container_dir: '/db'

# User/group for file/directory ownership
cardano_node_user: root
cardano_node_group: root

# Docker image
cdnsd_docker_image: 'ghcr.io/blinklabs-io/cdnsd:v{{ cdnsd_version }}'

# Docker container name
cdnsd_docker_container_name: cdnsd

# Port for host/container
cdnsd_container_port: 53
cdnsd_port: 20053

# Cardano network
cdnsd_network: preprod

# Configuration variables
cdnsd_indexer_script_address: "addr_test1vr75xezmpxastymx985l3gamuxrwqdwcfrcnjlygs55aynsqu3edq"
cdnsd_indexer_intercept_slot: "50844079"
cdnsd_indexer_intercept_hash: "81325118471fddb00a20327572b371aee7cce13b846a18500d011b9cefd2a34c"
3 changes: 3 additions & 0 deletions roles/cdnsd/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
galaxy_info: {}

dependencies: []
22 changes: 22 additions & 0 deletions roles/cdnsd/tasks/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Initialize cdnsd_docker_volumes fact
set_fact:
cdnsd_docker_volumes: '{{ cdnsd_docker_volumes | default([]) + [item] }}'
loop:
- '{{ cdnsd_db_dir }}:{{ cdnsd_db_container_dir }}'

- name: Create container
docker_container:
name: '{{ cdnsd_docker_container_name }}'
image: '{{ cdnsd_docker_image }}'
restart_policy: unless-stopped
env:
DNS_LISTEN_PORT: '{{ cdnsd_container_port }}'
STATE_DIR: '{{ cdnsd_db_container_dir }}'
INDEXER_SCRIPT_ADDRESS: '{{ cdnsd_indexer_script_address }}'
INDEXER_INTERCEPT_SLOT: '{{ cdnsd_indexer_intercept_slot | string }}'
INDEXER_INTERCEPT_HASH: '{{ cdnsd_indexer_intercept_hash }}'
INDEXER_NETWORK: '{{ cdnsd_network }}'
ports:
- '{{ cdnsd_port }}:{{ cdnsd_container_port }}'
volumes: '{{ cdnsd_docker_volumes | list }}'
23 changes: 23 additions & 0 deletions roles/cdnsd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Check install method
vars:
_allowed_install_methods: ['docker']
ansible.builtin.assert:
that:
- cdnsd_install_method in _allowed_install_methods
fail_msg: 'The specified install method ({{ cdnsd_install_method }}) is not one of the allowed values ({{ _allowed_install_methods | join(", ") }})'

# We use the node owner and group
- name: Create directories
ansible.builtin.file:
state: directory
path: '{{ item }}'
owner: '{{ cardano_node_user | string }}'
group: '{{ cardano_node_group | string }}'
mode: '0755'
loop:
- '{{ cdnsd_db_dir }}'

- name: Include docker-related tasks
ansible.builtin.include_tasks: docker.yml
when: cdnsd_install_method == 'docker'

0 comments on commit f6f2e96

Please sign in to comment.