diff --git a/README.md b/README.md index 82191f7..644e33a 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,7 @@ EOF sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +## Copy your ssh key to the machine +ssh-copy-id -p 2222 bapasqui@localhost + ``` diff --git a/ansible/inventory b/ansible/inventory new file mode 100644 index 0000000..d7d188f --- /dev/null +++ b/ansible/inventory @@ -0,0 +1,5 @@ +[ft_chatons] +vm1 ansible_host=localhost ansible_port=2222 ansible_user=bapasqui + +[ft_chatons:vars] +ansible_connection=ssh diff --git a/ansible/playbooks/install.yml b/ansible/playbooks/install.yml new file mode 100644 index 0000000..5afbffb --- /dev/null +++ b/ansible/playbooks/install.yml @@ -0,0 +1,23 @@ +--- +- name: Configure ft_chatons base VM + hosts: ft_chatons + become: yes + tasks: + - name: Update apt cache + apt: + update_cache: yes + + - name: Upgrade all packages + apt: + upgrade: dist + update_cache: yes + + - name: Install htop + apt: + name: + - htop + - nvim + state: present + + - name: Include Docker installation tasks + include_tasks: tasks/docker.yml diff --git a/ansible/playbooks/tasks/docker.yml b/ansible/playbooks/tasks/docker.yml new file mode 100644 index 0000000..977c648 --- /dev/null +++ b/ansible/playbooks/tasks/docker.yml @@ -0,0 +1,84 @@ +--- +- name: Check if Docker is already installed + command: docker --version + register: docker_check + ignore_errors: yes + changed_when: false + +- name: Display Docker installation status + debug: + msg: "Docker is already installed, skipping installation" + when: docker_check.rc == 0 + +- name: Update apt cache + apt: + update_cache: yes + when: docker_check.rc != 0 + +- name: Install required packages + apt: + name: + - ca-certificates + - curl + state: present + when: docker_check.rc != 0 + +- name: Create keyrings directory + file: + path: /etc/apt/keyrings + state: directory + mode: '0755' + when: docker_check.rc != 0 + +- name: Download Docker GPG key + get_url: + url: https://download.docker.com/linux/debian/gpg + dest: /etc/apt/keyrings/docker.asc + mode: '0644' + when: docker_check.rc != 0 + +- name: Get Debian version codename + shell: . /etc/os-release && echo "$VERSION_CODENAME" + register: debian_codename + changed_when: false + when: docker_check.rc != 0 + +- name: Add Docker repository + copy: + content: | + Types: deb + URIs: https://download.docker.com/linux/debian + Suites: {{ debian_codename.stdout }} + Components: stable + Signed-By: /etc/apt/keyrings/docker.asc + dest: /etc/apt/sources.list.d/docker.sources + mode: '0644' + when: docker_check.rc != 0 + +- name: Update apt cache after adding Docker repo + apt: + update_cache: yes + when: docker_check.rc != 0 + +- name: Install Docker packages + apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: present + when: docker_check.rc != 0 + +- name: Ensure Docker service is running + systemd: + name: docker + state: started + enabled: yes + +- name: Add user to docker group + user: + name: bapasqui + groups: docker + append: yes diff --git a/run b/run new file mode 100755 index 0000000..6787c95 --- /dev/null +++ b/run @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +case "$1" in + command) + ansible -i ansible/inventory ft_chatons -a "$2" + ;; + install) + ansible-playbook -i ansible/inventory ansible/playbooks/install.yml -K + ;; + *) + echo "Usage: $0 {start|delete|status|logs|restart|scale}" + exit 1 +esac + + +