from audricd@lemmy.ml to selfhosted@lemmy.world on 21 Nov 19:45
https://lemmy.ml/post/39297898
Hello, Does anyone have by any chance an ansible playbook to setup docker on a debian trixie?
This is my first experience with Ansible, i thought this would be easy and straightforward. I used existing ones for debian 12 as template and yes, with ai, and taking things from other templates, i am trying to make this work. but for the life of me, i cannot crack this.
i began with the most simple steps:
- name: install Docker
hosts: all
become: true
tasks:
- name: Install apt-transport-https
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- lsb-release
- gnupg
state: latest
update_cache: true
- name: Create keyrings directory
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Add Docker GPG key
ansible.builtin.shell: |
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
args:
creates: /etc/apt/keyrings/docker.gpg
- name: Add Docker repository
ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian trixie stable"
state: present
filename: docker
- name: Install Docker
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: latest
update_cache: true
and added some debug stuff that really didnt help that much:
- name: Install Docker Engine and Docker Compose on Debian (Ansible WebUI compatible)
hosts: all
become: true
become_user: root
vars:
docker_packages:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
tasks:
- name: Ensure required packages are installed
apt:
name:
- ca-certificates
- curl
- gnupg
update_cache: yes
state: present
delegate_to: "{{ inventory_hostname }}"
- name: Ensure /etc/apt/keyrings exists
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
delegate_to: "{{ inventory_hostname }}"
- name: Get system architecture for Docker repo
ansible.builtin.command: dpkg --print-architecture
register: dpkg_architecture
changed_when: false
delegate_to: "{{ inventory_hostname }}"
- name: Download Docker GPG key
ansible.builtin.get_url:
url: https://download.docker.com/linux/debian/gpg
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Check if GPG key exists
ansible.builtin.stat:
path: /etc/apt/keyrings/docker.asc
register: gpg_key_stat
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Show GPG key status
ansible.builtin.debug:
msg: "GPG key exists: {{ gpg_key_stat.stat.exists }}, Size: {{ gpg_key_stat.stat.size | default('N/A') }}"
- name: DEBUG - List keyrings directory
ansible.builtin.command: ls -lah /etc/apt/keyrings/
register: keyrings_list
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Show keyrings directory contents
ansible.builtin.debug:
var: keyrings_list.stdout_lines
- name: Add Docker APT repository (correct for Debian 13)
ansible.builtin.apt_repository:
repo: "deb [arch={{ dpkg_architecture.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
filename: docker
state: present
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Check if repo file exists
ansible.builtin.stat:
path: /etc/apt/sources.list.d/docker.list
register: repo_file_stat
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Show repo file status
ansible.builtin.debug:
msg: "Repo file exists: {{ repo_file_stat.stat.exists }}"
- name: DEBUG - Show repo file contents if exists
ansible.builtin.command: cat /etc/apt/sources.list.d/docker.list
register: repo_contents
when: repo_file_stat.stat.exists
failed_when: false
delegate_to: "{{ inventory_hostname }}"
- name: DEBUG - Display repo contents
ansible.builtin.debug:
var: repo_contents.stdout_lines
when: repo_file_stat.stat.exists
- name: Update apt cache after adding repo
apt:
update_cache: yes
delegate_to: "{{ inventory_hostname }}"
- name: Install Docker packages
apt:
name: "{{ docker_packages }}"
state: present
delegate_to: "{{ inventory_hostname }}"
- name: Enable & start Docker
service:
name: docker
state: started
enabled: yes
delegate_to: "{{ inventory_hostname }}"
but everytime it fails at adding the package because its not found. because the repo was not added, my keyrings folder is miserably empty.
the target server has only root. so no user confusion there. yes, i know. bad practice. but its a learning exercise and its a lxc within my home network not internet exposed.
PLAY [Install Docker Engine and Docker Compose on Debian (Ansible WebUI compatible)] ***
TASK [Gathering Facts] *********************************************************
[1;35m[WARNING]: Host 'anytype.lab' is using the discovered Python interpreter at '/usr/bin/python3.13', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.19/reference_appendices/interpreter_discovery.html for more information.[0m
[0;32mok: [anytype.lab][0m
TASK [Ensure required packages are installed] **********************************
[0;33mchanged: [anytype.lab][0m
TASK [Ensure /etc/apt/keyrings exists] *****************************************
[0;32mok: [anytype.lab][0m
TASK [Get system architecture for Docker repo] *********************************
[0;36mskipping: [anytype.lab][0m
TASK [Download Docker GPG key] *************************************************
[0;33mchanged: [anytype.lab][0m
TASK [DEBUG - Check if GPG key exists] *****************************************
[0;32mok: [anytype.lab][0m
TASK [DEBUG - Show GPG key status] *********************************************
[0;32mok: [anytype.lab] => {[0m
[0;32m "msg": "GPG key exists: False, Size: N/A"[0m
[0;32m}[0m
TASK [DEBUG - List keyrings directory] *****************************************
[0;36mskipping: [anytype.lab][0m
TASK [DEBUG - Show keyrings directory contents] ********************************
[0;32mok: [anytype.lab] => {[0m
[0;32m "keyrings_list.stdout_lines": [][0m
[0;32m}[0m
TASK [Add Docker APT repository (correct for Debian 13)] ***********************
[0;33mchanged: [anytype.lab][0m
TASK [DEBUG - Check if repo file exists] ***************************************
[0;32mok: [anytype.lab][0m
TASK [DEBUG - Show repo file status] *******************************************
[0;32mok: [anytype.lab] => {[0m
[0;32m "msg": "Repo file exists: False"[0m
[0;32m}[0m
TASK [DEBUG - Show repo file contents if exists] *******************************
[0;36mskipping: [anytype.lab][0m
TASK [DEBUG - Display repo contents] *******************************************
[0;36mskipping: [anytype.lab][0m
TASK [Update apt cache after adding repo] **************************************
[0;33mchanged: [anytype.lab][0m
TASK [Install Docker packages] *************************************************
[0;31m[ERROR]: Task failed: Module failed: No package matching 'docker-ce' is available[0m
[0;31mOrigin: /tmp/ansible-webui/repositories/1_ansibleplaybooksrepo/playbooks/debian13docker.yml:100:7[0m
[0;31m[0m
[0;31m 98 delegate_to: "{{ inventory_hostname }}"[0m
[0;31m 99[0m
[0;31m100 - name: Install Docker packages[0m
[0;31m ^ column 7[0m
[0;31m[0m
[0;31mfatal: [anytype.lab]: FAILED! => {"changed": false, "msg": "No package matching 'docker-ce' is available"}[0m
PLAY RECAP *********************************************************************
[0;31manytype.lab[0m : [0;32mok=11 [0m [0;33mchanged=4 [0m unreachable=0 [0;31mfailed=1 [0m [0;36mskipped=4 [0m rescued=0 ignored=0
I am using ansible-webui.oxl.app although i doubt it has any effect whatsoever. but then again, i know next to nothing of ansible as of yet. so, for sure: what i am missing is incredibly dumb.
any help will be greatly appreciated.
#selfhosted
threaded - newest
I’d connect vis SSH and manually inspect the files that it’s supposed to be creating. Does
apt updateshow any errors?none that i can see<img alt="" src="https://lemmy.ml/pictrs/image/874da127-d64b-428c-a38a-ab10be6b0c73.png">
I do, but need my laptop. The bit you need to fix is adding a new deb repo, will try and post tomorrow now
you need to use deb822 as the repo module, like this
- name: Setup deb822 formatted repositorie ansible.builtin.deb822_repository: name: php types: deb uris: https://download.docker.com/linux/debian components: stable suites: "{{ ansible_distribution_release }}" signed_by: https://download.docker.com/linux/debian/gpg state: present enabled: true when: (ansible_distribution == 'Debian' and ansible_distribution_major_version >= '13')hum unfortunately either im doing something else wrong or its not working for me
--- - name: Install Docker Engine and Docker Compose on Debian (Ansible WebUI compatible) hosts: all become: true become_user: root vars: docker_packages: - docker-ce - docker-ce-cli - containerd.io - docker-buildx-plugin - docker-compose-plugin tasks: - name: Ensure required packages are installed apt: name: - ca-certificates - curl - gnupg update_cache: yes state: present delegate_to: "{{ inventory_hostname }}" - name: Ensure /etc/apt/keyrings exists file: path: /etc/apt/keyrings state: directory mode: '0755' delegate_to: "{{ inventory_hostname }}" - name: Get system architecture for Docker repo ansible.builtin.command: dpkg --print-architecture register: dpkg_architecture changed_when: false delegate_to: "{{ inventory_hostname }}" - name: Setup deb822 formatted repositorie ansible.builtin.deb822_repository: name: php types: deb uris: https://download.docker.com/linux/debian components: stable suites: "{{ ansible_distribution_release }}" signed_by: https://download.docker.com/linux/debian/gpg state: present enabled: true when: (ansible_distribution == 'Debian' and ansible_distribution_major_version >= '13') - name: Download Docker GPG key ansible.builtin.get_url: url: https://download.docker.com/linux/debian/gpg dest: /etc/apt/keyrings/docker.asc mode: '0644' delegate_to: "{{ inventory_hostname }}" - name: DEBUG - Check if GPG key exists ansible.builtin.stat: path: /etc/apt/keyrings/docker.asc register: gpg_key_stat delegate_to: "{{ inventory_hostname }}" - name: DEBUG - Show GPG key status ansible.builtin.debug: msg: "GPG key exists: {{ gpg_key_stat.stat.exists }}, Size: {{ gpg_key_stat.stat.size | default('N/A') }}" - name: DEBUG - List keyrings directory ansible.builtin.command: ls -lah /etc/apt/keyrings/ register: keyrings_list delegate_to: "{{ inventcould you maybe please send me the whole thing?
Will do when I get home
You are adding a new repo, but you should know that the debian repos already contain docker (via
docker.io) anddocker-compose.oh! I wasnt aware of that? i see its slightly outdated, it has version 26 as opposed to 29 from its official source. at least in trixie stable<img alt="" src="https://lemmy.ml/pictrs/image/dbcc1501-feb4-45b7-805c-de457765bc15.png"><img alt="" src="https://lemmy.ml/pictrs/image/3264767d-1ae8-4989-8291-22df72172df1.png">
Then crack open the documentation and learn how to actually write and use ansible
WOW. I HAVE NOT THOUGHT OF THAT!!!111