Hello @JimVincent and @comodoro!
Here is a simple way to deploy your software stack on the Lambda Cloud using Ansible.
eg. create “ready_to_work.yml”
---
# you can run this as follows:
# ansible-playbook --ssh-common-args='-o StrictHostKeyChecking=no' ready_to_work.yml -i lambda_cloud_instance_ip,
# DON'T FORGET THE , IN THE END!
# eg. ansible-playbook --ssh-common-args='-o StrictHostKeyChecking=no' ready_to_work.yml -i 10.0.0.2,
- hosts: all
remote_user: ubuntu
vars:
ansible_ssh_private_key_file: "~/.ssh/your-private-ssh-key-for-lambda-instances"
github_username: put_username_here
github_token: put_password_here
github_repo: put_repo_name_here
tasks:
# Here, we use the variables set above
# We clone the repo to the home directory of the user
- name: Checkout Your Code From Github Using Ansible.
git:
repo: "https://{{ github_token }}@github.com/{{ github_username }}/{{ github_repo }}.git"
dest: "~/{{ github_repo }}"
- name: Install apt packages
ansible.builtin.apt:
name: "{{ item }}"
state: present
update_cache: yes
loop:
- package1
- package2
- name: Install pip packages
ansible.builtin.pip:
name: "{{ item }}"
loop:
- package1
- package2
# Or start a Docker container
- name: Start Docker container
docker_container:
name: mycontainer
state: present
image: ubuntu:22.04
command: sleep infinity
You can also create a bash script to check if the Lambda instance has booted (by checking if port 22 is active) and then run the ansible script on it.
Create bash_script.sh
until nc -vzw 2 $1 22; do sleep 2; done
ansible-playbook --ssh-common-args='-o StrictHostKeyChecking=no' rready_to_work.yml -i $1,
Run it like this:
$ bash bash_script.sh <instance_ip>
Best,
Yanos