add: automatisation for base install
This commit is contained in:
parent
0c1a548762
commit
56116066b7
|
|
@ -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
5
ansible/inventory
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[ft_chatons]
|
||||
vm1 ansible_host=localhost ansible_port=2222 ansible_user=bapasqui
|
||||
|
||||
[ft_chatons:vars]
|
||||
ansible_connection=ssh
|
||||
23
ansible/playbooks/install.yml
Normal file
23
ansible/playbooks/install.yml
Normal 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
|
||||
84
ansible/playbooks/tasks/docker.yml
Normal file
84
ansible/playbooks/tasks/docker.yml
Normal 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
|
||||
Loading…
Reference in a new issue