testnet-ops/stack-orchestrator-setup/setup-docker.yml
Prathamesh Musale cd314d2fdf Add Ansible playbooks to setup Docker and stack orchestrator (#6)
Part of [Automate testnet nitro deployments using Ansible](https://www.notion.so/Automate-testnet-nitro-deployments-using-Ansible-0d15579430204b8daba9a8aa31e07568)

Add Ansible playbooks to:
- Setup Docker if not present
- Setup Stack Orchestrator if not present

Co-authored-by: Adw8 <adwaitgharpure@gmail.com>
Co-authored-by: Neeraj <neeraj.rtly@gmail.com>
Reviewed-on: cerc-io/testnet-ops#6
Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
2024-09-12 04:43:53 +00:00

92 lines
2.2 KiB
YAML

- name: Set up Docker
hosts: "{{ target_host }}"
become: yes
vars:
target_host: "localhost"
docker_gpg_key_url: "https://download.docker.com/linux/ubuntu/gpg"
docker_gpg_key_path: "/etc/apt/keyrings/docker.asc"
tasks:
- name: Check if Docker is installed
command: which docker
register: is_docker_present
ignore_errors: yes
- block:
- name: Exit if docker is present
debug:
msg: "Docker already on host, ending play"
- meta: end_play
when: is_docker_present.rc == 0
- name: Update apt cache
apt:
update_cache: yes
- name: Install prerequisites
apt:
name:
- ca-certificates
- curl
state: present
- name: Ensure keyrings directory exists
file:
path: "/etc/apt/keyrings"
state: directory
mode: '0755'
- name: Download Docker GPG key
get_url:
url: "{{ docker_gpg_key_url }}"
dest: "{{ docker_gpg_key_path }}"
mode: '0644'
- name: Get system architecture
shell: dpkg --print-architecture
register: system_arch
- name: Add Docker repository
apt_repository:
repo: "deb [arch={{ system_arch.stdout }} signed-by={{ docker_gpg_key_path }}] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable"
state: present
filename: docker
- name: Update apt cache
apt:
update_cache: yes
- name: Install Docker packages
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: latest
notify: Restart Docker
- name: Add user to docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: true
- name: Verify Docker installation by running the hello world image
command: docker run hello-world
register: hello_world_output
ignore_errors: true
become: no
- name: Display hello-world output
debug:
var: hello_world_output.stdout_lines
handlers:
- name: Restart Docker
service:
name: docker
state: restarted