add: automatisation for base install

This commit is contained in:
Haletran 2026-02-19 22:23:51 +01:00
parent 0c1a548762
commit 56116066b7
5 changed files with 131 additions and 0 deletions

View file

@ -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
```

5
ansible/inventory Normal file
View file

@ -0,0 +1,5 @@
[ft_chatons]
vm1 ansible_host=localhost ansible_port=2222 ansible_user=bapasqui
[ft_chatons:vars]
ansible_connection=ssh

View file

@ -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

View file

@ -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

16
run Executable file
View file

@ -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