Skip to content

Commit

Permalink
Ansible: dev only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hijohnnylin committed May 16, 2024
1 parent ec70cea commit 027460f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
36 changes: 36 additions & 0 deletions scripts/ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export WANDB_API_KEY=[Paste Wandb API Key]
pip install ansible
ansible --version
cd scripts/ansible
ansible-galaxy collection install -r util/requirements.yml
```

Expand Down Expand Up @@ -99,6 +100,41 @@ ansible-playbook playbooks/setup.yml
ansible-playbook playbooks/train_sae.yml
```

#### Run Instance for Development

This brings up an instance with SAELens on it that has everything configured to run a job, including mounted S3. You will need to shut down the instance yourself when you're done with it.
1) Make sure you've copied the latest `scripts/ansible/configs-example` to `scripts/ansible/config`.
2) Modify `scripts/ansible/config/dev.yml` with the instance type you wish to launch, then save.

```
cd scripts/ansible
ansible-playbook run-dev.yml
# wait for run-dev.yml to complete (~7 minutes)
# get the IP address to ssh into
ansible-inventory --list --yaml tag_service__dev | grep public_ip_address
ssh -i ~/.ssh/saelens_ansible ubuntu@[PASTE_PUBLIC_IP_ADDRESS]
```

Once you're SSH'ed into the instance, the directories are:
```
# s3 mounted bucket directory, which should contain your bucket as its sole subdirectory
cd /mnt/s3
ls
# SAELens git repo - main branch
cd /home/ubuntu/SAELens
```

**Remember to terminate your instance when you're done.**
You can terminate the instance from the EC2 console. Alternatively, the instance has been configured to terminate on shutdown, so from SSH you can just run:
```
sudo shutdown -h now
```
You should still double check that the instance does indeed terminate from EC2 Console, just in case shutdown failed for some reason.

### TODO
- make config scripts that makes the config sweep files automatically
- should do async so that canceling ansible doesnt cancel the job
Expand Down
1 change: 1 addition & 0 deletions scripts/ansible/configs_example/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
instance_type: g6.xlarge
2 changes: 1 addition & 1 deletion scripts/ansible/configs_example/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
s3_bucket_name: johnny.saes.1234

# Change if you need a specific version
saelens_version_or_branch: v2.1.1
saelens_version_or_branch: main

#################### DON'T CHANGE THE FOLLOWING

Expand Down
30 changes: 30 additions & 0 deletions scripts/ansible/playbooks/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

- name: "Launch dev instance"
hosts: localhost
vars_files:
- "{{ lookup('env', 'PWD') ~ '/configs/shared.yml' }}"
tasks:
- name: Launch the EC2 Instance
include_tasks: "{{ lookup('env', 'PWD') ~ '/tasks/launch_ec2_instance.yml' }}"
vars:
config_file: "{{ lookup('env', 'PWD') ~ '/configs/dev.yml' }}"
service_name: "dev"
job_name: "dev"

- name: "Configure instance for job {{ job_name }}"
hosts: tag_service__dev:&tag_job__{{ job_name }}
gather_facts: true
vars:
ansible_user: ubuntu
ansible_ssh_private_key_file: "{{ ssh_key_path }}"
ansible_python_interpreter: auto_silent
instance_storage_path: "{{ instance_storage_path }}"
s3_local_cache_path: "{{ instance_storage_path }}/s3-local-cache"
service_name: "dev"
job_name: "dev"
vars_files:
- "{{ lookup('env', 'PWD') ~ '/configs/shared.yml' }}"
tasks:
- name: Configure the EC2 Instance
include_tasks: "{{ lookup('env', 'PWD') ~ '/tasks/configure_ec2_instance.yml' }}"
16 changes: 16 additions & 0 deletions scripts/ansible/run-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

- name: Run Setup
ansible.builtin.import_playbook: playbooks/setup.yml

- name: Run Development Instance
ansible.builtin.import_playbook: playbooks/dev.yml

- name: Clear ansible.log
hosts: localhost
tasks:
- name: Clear ansible.log
ansible.builtin.copy:
content: ""
dest: "ansible.log"
mode: '0644'
3 changes: 2 additions & 1 deletion scripts/ansible/util/aws_ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ filters:
instance-state-name: running
tag:service:
- cache_acts
- train_sae
- train_sae
- dev

0 comments on commit 027460f

Please sign in to comment.