Skip to content

Commit 6e9f37f

Browse files
authored
Ability for nodes to be able to self bootstrap (#553)
1 parent 71e9608 commit 6e9f37f

16 files changed

+256
-26
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: Install requirements on the host
2+
remote_user: ubuntu
3+
# Ability to override host, useful to running playbook in local mode
4+
hosts: "{{ target_hosts | default('all') }}"
5+
tasks:
6+
- name: Install collections and roles together
7+
community.general.ansible_galaxy_install:
8+
type: both
9+
requirements_file: "{{ playbook_dir }}/requirements.yaml"

infrastructure/ansible/provision_canary.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: Provision Canary
22
remote_user: ubuntu
3-
hosts: tag_Type_compute
3+
hosts: "{{ target_hosts | default('tag_Type_compute') }}"
44
vars:
55
canary_dir: /opt/local/canary
66
repo_dir: "{{ canary_dir }}/repo"

infrastructure/ansible/provision_compute_instance.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: Provision Bacalhau
22
remote_user: ubuntu
3-
hosts: tag_Type_compute:&tag_Env_prod
3+
hosts: "{{ target_hosts | default('tag_Type_compute') }}"
44
vars:
55
nvidia_distribution: ubuntu2004
66
nvidia_container_toolkit_key_path: /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg

infrastructure/ansible/provision_compute_only.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- name: Provision Bacalhau Compute Instance
22
remote_user: ubuntu
3-
hosts: tag_Type_compute_only
3+
# Ability to override host, useful to running playbook in local mode
4+
hosts: "{{ target_hosts | default('tag_Type_compute_only') }}"
45
vars:
56
nvidia_distribution: ubuntu2004
67
ipfs_version: "0.18.0"
@@ -47,13 +48,13 @@
4748
- name: flush handlers
4849
ansible.builtin.meta: flush_handlers
4950

50-
# Required docker since IPFS runs in container
51+
# Install IPFS
5152
- name: Install IPFS
5253
ansible.builtin.include_tasks: tasks/install_ipfs_tasks.yaml
5354
tags: ipfs_install
5455

5556
# Run Bacalhau agent
56-
- name: Run Baclahau container
57+
- name: Run Baclahau agent
5758
ansible.builtin.include_tasks: tasks/install_bacalhau_tasks.yaml
5859
tags: bacalhau
5960

infrastructure/ansible/provision_jupyter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: Provision Jupyter Notebook Instances
22
remote_user: ubuntu
3-
hosts: tag_Type_jupyter_notebook
3+
hosts: "{{ target_hosts | default('tag_Type_jupyter_notebook') }}"
44
vars:
55
letsencrypt_email: "josh@labdao.xyz"
66
letsencrypt_domain: "jupyter.labdao.xyz"

infrastructure/ansible/provision_receptor.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: Provision Receptor
22
remote_user: ubuntu
3-
hosts: tag_Type_receptor
3+
hosts: "{{ target_hosts | default('tag_Type_receptor') }}"
44
vars:
55
plex_dir: /opt/local/plex
66
receptor_dir: /opt/local/receptor

infrastructure/ansible/provision_requester.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- name: Provision Bacalhau Requester
22
remote_user: ubuntu
3-
hosts: tag_Type_requester
3+
hosts: "{{ target_hosts | default('tag_Type_requester') }}"
44
vars:
55
ipfs_version: "0.18.0"
66
ipfs_path: "/opt/ipfs"

infrastructure/ansible/tasks/install_bacalhau_tasks.yaml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,53 @@
77
no_log: true
88
check_mode: false
99

10+
- name: Set fact for currently installed version
11+
ansible.builtin.set_fact:
12+
bacalhau_installed_version: "{{ existing_bacalhau_version.stdout.split('Server Version: ')[1] }}"
13+
when: existing_bacalhau_version.stdout != ''
14+
1015
- name: Print installed kubo version
1116
ansible.builtin.debug:
12-
msg: "Installed bacalhau version: {{ existing_bacalhau_version.stdout.split('Server Version: ')[1] }} vs {{ bacalhau_version }}"
13-
when: existing_kubo_version.stdout != ''
17+
msg: "Installed bacalhau version: {{ bacalhau_installed_version }} vs {{ bacalhau_version }}"
18+
when: bacalhau_installed_version is defined
1419

15-
# Compare the latest version of bacalhau with the version that is already installed, if any.
16-
- name: Install or update bacalhau
17-
when:
18-
"(existing_bacalhau_version.stdout == '') or (existing_bacalhau_version.stdout.split('Server Version: ')[1] != bacalhau_version)"
20+
- name: Only do this if bacalhau isnt installed or upgrade is needed
21+
when: bacalhau_installed_version is undefined or bacalhau_installed_version != bacalhau_version
1922
block:
23+
- name: Fetch AWS EC2 Metadata facts
24+
amazon.aws.ec2_metadata_facts:
25+
26+
- name: Print environment info
27+
ansible.builtin.debug:
28+
msg: "Running on environment: {{ ansible_ec2_tags_instance_Env }}"
29+
when: ansible_ec2_tags_instance_Env is defined
30+
31+
- name: Set fact when its prod node
32+
ansible.builtin.set_fact:
33+
bacalhau_hostname: "bacalhau.labdao.xyz"
34+
requester_hostname: "requester.labdao.xyz"
35+
when: ansible_ec2_tags_instance_Env is defined and ansible_ec2_tags_instance_Env | lower == "prod"
36+
37+
- name: Set fact when its non-prod node
38+
ansible.builtin.set_fact:
39+
bacalhau_hostname: "bacalhau.{{ ansible_ec2_tags_instance_Env | lower }}.labdao.xyz"
40+
requester_hostname: "requester.{{ ansible_ec2_tags_instance_Env | lower }}.labdao.xyz"
41+
when: ansible_ec2_tags_instance_Env is defined and ansible_ec2_tags_instance_Env | lower != "prod"
42+
43+
# Bacalhau PeerID, example `curl -s bacalhau.staging.labdao.xyz:1234/node_info | jq -r '.PeerInfo.ID'`
44+
- name: Determine requester bacalhau peer id
45+
ansible.builtin.uri:
46+
url: "http://{{ bacalhau_hostname }}:1234/node_info"
47+
return_content: true
48+
register: bacalhau_output
49+
when: bacalhau_hostname is defined
50+
51+
- name: Set requester_peer url
52+
ansible.builtin.set_fact:
53+
# requester_peer: /dns4/requester.staging.labdao.xyz/tcp/1235/p2p/QmeLa2fx2FMNDWbeY3UqjELc1MbKwNxggcmdBmLZepY6VK
54+
requester_peer: "/dns4/{{ requester_hostname }}/tcp/1235/p2p/{{ bacalhau_output.content | from_json | community.general.json_query('PeerInfo.ID') }}"
55+
when: requester_hostname is defined
56+
2057
- name: Download Bacalhau binary
2158
become: true
2259
ansible.builtin.unarchive:

infrastructure/ansible/tasks/install_ipfs_tasks.yaml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@
5656
line: IPFS_PATH={{ ipfs_path }}
5757

5858
- name: Initiazlie IPFS
59+
become: true
60+
become_user: ubuntu
5961
ansible.builtin.command:
6062
cmd: ipfs init
6163
creates: "{{ ipfs_path }}/config"
6264
environment:
6365
IPFS_PATH: "{{ ipfs_path }}"
6466

6567
- name: Configure IPFS
68+
become: true
69+
become_user: ubuntu
6670
ansible.builtin.shell: |
6771
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
6872
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
@@ -85,7 +89,6 @@
8589
enabled: true
8690

8791
- name: Wait for IPFS to be healthy
88-
become: true
8992
command:
9093
cmd: ipfs --api=/ip4/127.0.0.1/tcp/5001 dag stat /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
9194
register: ipfs_healthcheck
@@ -97,7 +100,44 @@
97100
when: bacalhau_node_type == "compute"
98101
tags: ipfs_swarm
99102
block:
100-
- name: Run ipfs swarm inside container
103+
- name: Fetch AWS EC2 Metadata facts
104+
amazon.aws.ec2_metadata_facts:
105+
106+
- name: Print environment info
107+
ansible.builtin.debug:
108+
msg: "Running on environment: {{ ansible_ec2_tags_instance_Env }}"
109+
when: ansible_ec2_tags_instance_Env is defined
110+
111+
- name: Set fact when its prod node
112+
ansible.builtin.set_fact:
113+
bacalhau_hostname: "bacalhau.labdao.xyz"
114+
requester_hostname: "requester.labdao.xyz"
115+
when: ansible_ec2_tags_instance_Env is defined and ansible_ec2_tags_instance_Env | lower == "prod"
116+
117+
- name: Set fact when its non-prod node
118+
ansible.builtin.set_fact:
119+
bacalhau_hostname: "bacalhau.{{ ansible_ec2_tags_instance_Env | lower }}.labdao.xyz"
120+
requester_hostname: "requester.{{ ansible_ec2_tags_instance_Env | lower }}.labdao.xyz"
121+
when: ansible_ec2_tags_instance_Env is defined and ansible_ec2_tags_instance_Env | lower != "prod"
122+
123+
# curl -s -X POST http://bacalhau.staging.labdao.xyz:5001/api/v0/config/show | jq -r '.Identity.PeerID'
124+
- name: Determine ipfs peer id
125+
ansible.builtin.uri:
126+
url: "http://{{ bacalhau_hostname }}:5001/api/v0/config/show"
127+
method: POST
128+
return_content: true
129+
register: ipfs_output
130+
when: bacalhau_hostname is defined
131+
132+
- name: Set requester_peer url
133+
ansible.builtin.set_fact:
134+
# IPFS PeerID, `curl -s -X POST http://bacalhau.staging.labdao.xyz:5001/api/v0/config/show | jq -r '.Identity.PeerID'`
135+
requester_ipfs_peer: "/dns4/{{ requester_hostname }}/tcp/4001/p2p/{{ ipfs_output.content | from_json | community.general.json_query('Identity.PeerID') }}"
136+
when: requester_hostname is defined
137+
138+
- name: Run ipfs swarm
139+
become: true
140+
become_user: ubuntu
101141
command:
102142
cmd: ipfs swarm connect {{ requester_ipfs_peer }}
103143
environment:

infrastructure/ansible/vars/prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
receptor_url: http://ip-172-31-82-127.ec2.internal:8080/judge
34
requester_peer: /ip4/172.31.90.74/tcp/1235/p2p/QmbETsVtL1sQ97KKV1jPQA5ng8RSyzPWUiDgRBQp7AcjRt
45
requester_ipfs_peer: /ip4/172.31.90.74/tcp/4001/p2p/12D3KooWAjYbsjXAQWqPRCPTTaMkDkUjhschznkLrDoKUyfQvHAP

0 commit comments

Comments
 (0)