From f6f2e969a2efa28c209c9311f266df070c1a872b Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Wed, 13 Mar 2024 18:31:01 -0400 Subject: [PATCH] feat: cdnsd role (#67) Signed-off-by: Chris Gianelloni --- roles/cdnsd/README.md | 50 +++++++++++++++++++++++++++++++++++ roles/cdnsd/defaults/main.yml | 35 ++++++++++++++++++++++++ roles/cdnsd/meta/main.yml | 3 +++ roles/cdnsd/tasks/docker.yml | 22 +++++++++++++++ roles/cdnsd/tasks/main.yml | 23 ++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 roles/cdnsd/README.md create mode 100644 roles/cdnsd/defaults/main.yml create mode 100644 roles/cdnsd/meta/main.yml create mode 100644 roles/cdnsd/tasks/docker.yml create mode 100644 roles/cdnsd/tasks/main.yml diff --git a/roles/cdnsd/README.md b/roles/cdnsd/README.md new file mode 100644 index 0000000..df9477e --- /dev/null +++ b/roles/cdnsd/README.md @@ -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). diff --git a/roles/cdnsd/defaults/main.yml b/roles/cdnsd/defaults/main.yml new file mode 100644 index 0000000..30cdcf4 --- /dev/null +++ b/roles/cdnsd/defaults/main.yml @@ -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" diff --git a/roles/cdnsd/meta/main.yml b/roles/cdnsd/meta/main.yml new file mode 100644 index 0000000..e8fe48d --- /dev/null +++ b/roles/cdnsd/meta/main.yml @@ -0,0 +1,3 @@ +galaxy_info: {} + +dependencies: [] diff --git a/roles/cdnsd/tasks/docker.yml b/roles/cdnsd/tasks/docker.yml new file mode 100644 index 0000000..4b22532 --- /dev/null +++ b/roles/cdnsd/tasks/docker.yml @@ -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 }}' diff --git a/roles/cdnsd/tasks/main.yml b/roles/cdnsd/tasks/main.yml new file mode 100644 index 0000000..b615e62 --- /dev/null +++ b/roles/cdnsd/tasks/main.yml @@ -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'