# TODO
๐ bridged from !ansible@lemmy.world by Tidepool
# TODO
๐ bridged from !ansible@lemmy.world by Tidepool
Docker setup for debian 13 trixie Ansible Playbook
cross-posted from: 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: trueand 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=0I am using https://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.
Use nested/dynamic variables in template
Hello everyone, I need some help with using variables in jinja templates. Disclaimer: I am pretty new to ansible, so feel free to tell me that I understood something wrong.
I try to use a variable inside a variable, that gets called from a jinja template I have my network ranges defined in the global vars
vars/global.yml
networks:
lclsrv:
ipv4: 10.10.10.0/24
ext:
ipv4: 1234.123.123.12/xThen I createt a role called "iptables", with which I would like to manage all iptables on all hosts. In its defaults, there are (obviously) the default_iptable_rules defined.
Besides them, there are host specific iptables, which are also defined in the defaults, like this e.g:
host1_rules: - "-A INPUT -p tcp --dport 80 -j ACCEPT" - "-A INPUT -p tcp --dport 443 -j ACCEPT"
In some of the host specific rules I have to define a network range from the global vars, like:
host2_rules:
- "-A INPUT -p tcp -s {{ networks['ext']['ipv4'] }} --dport 6000 -j ACCEPT"In the template I try to insert these host specific rules like this:
{% for rule in vars[inventory_hostname + '_rules'] %}
{{rule}}
{% endfor %}I think I understood, that this "structure" is not the recommended ansible way. Until now we got all host specific iptables organized in there host files, which is probably the clean way of doing this (?) But with lots of hosts this got very messy, so I want to manage them in one single file, to have them all together.
The for loop itself works as expected, but the variables won't get processed. The resulting /etc/iptables/rules.v4 for host2 will look exactly like this:
-A INPUT -p tcp -s {{ networks['ext']['ipv4'] }} --dport 6000 -j ACCEPT
So the template get the element from the host specific variable as a string but won't interpret the variable inside of this string.
I looked at suggestions to use the lookup function, but this also did not work. When I replaced the variable inside of the rule-string with the lookup, the lookup-functiongot printed out, just like the variable in "{{}}".
I am struggling with this sinc last monday and I would appreciate any help! Tanks!
Ansible on Windows - is it viable as a "poor man" solution to RMM?
Has anyone had success with using Ansible to manage Windows?
Homeserver Ansible Playbook
cross-posted from: https://lemmy.dbzer0.com/post/19839436
After getting fed up with TrueNAS (after it borked itself for the third time and I would have had to set it up AGAIN) I decided to learn Ansible and write a playbook to setup my homeserver that way. I wanted to share this playbook with you in case someone might find it useful for their own setup and maybe someone has some tips on things I could improve. This server will not be exposed to the public/internet. If I want to access a service on it from outside my home network I have Wireguard setup on my router to connect to my home network from anywhere. Keep in mind that I'm relatively new to sysadmin stuff etc so don't be too harsh please ๐
How to parallelize execution on a single host?
I'm setting up an application using containers with ansible. I want to be able to set up the same application multiple times with a different set of variables. Is there a way how I could do this in parallel on a single host? I know I could deploy the same application n times on n different hosts, but what about n times on a single host? Is something like this possible? Doing it sequential obviously works, but it doesn't scale well.
Jeff Geerling giving away his book on Ansible
Jeff Geerling in response to RedHats shenanigans is giving away his book on Ansible. Source: https://twitter.com/geerlingguy/status/1674554543797829633
pick a leader from all the hosts in the inventory
I have an inventory of hosts, and from them, one of the tasks should choose a leader by running a command on each until one of the machines produces an expected output (json value.)
I want some code to run on that leader to initialize it, and then I want some of the other roles to delegate some tasks to that leader.
Not sure how to do this?
Should I use dynamic inventory to analyze a group of hosts, and create a new group (can you run built_in.command in dynamic inventory? Should I write a role task that runs the identifying command on each host, capturing the result globally if it returns what I want (but then running on each host even if I have found my leader?)
Which modules for BTRFS or ZFS setup with Ansible?
Hello,
I need some help here. I've been trying to write my own Ansible playbook to setup my homeserver. The storage devices on this server are 1 NVMe SSD and 2 HDDs which I want to setup as a mirror. I want to setup all storage devices as either BTRFS or ZFS but I'm having trouble finding the correct modules to use in Ansible for this.
I have also found some roles in Ansible Galaxy but those are either not explained enough for me to use and seem overwhelming to use (especially in comparison to the terminal commands that are needed to setup the BTRFS volumes or ZFS pools). But just using the builtin command module in Ansible somehow feels wrong and not the right way to go about this.
Can someone point me in the right direction? Right now I think I will prefer using BTRFS.
How to share files between roles
We use AAP to deploy roles. The roles are in Git. I now have 2 roles that need to deploy the same files and templates, and of course I don't want to keep 2 versions in Git. How could I solve that?
Including/Importing an Ansible role w/ handlers more than once
cross-posted from: https://lemmy.ml/post/4593804
Originally discussed on Matrix. โโโ TLDR; Ansible handlers are added to the global namespace. โโโ Suppose you've got a role which defines a handler
MyHandler:- name: MyHandler ... listen: "some-topic"Each time you
import/includeyour role, a new reference toMyHandleris added to the global namespace. As a result, when younotifyyour handler via the topics itlistens to (ienotify: "some-topic"), all the references toMyHandlerwill be executed by Ansible. If that's not what you want, you shouldnotifythe handler by name (ienotify: MyHandler) in which case Ansible will stop searching for other references as soon as it finds the first occurrence ofMyHandler. That meansMyHandlerwill be executed only once.
ssh: Can't Open user config file, but the file exists
I've just moved all my ansible control to a new host, but when I try to run a playbook that worked on the old host, I'm getting this error:
"msg": "Failed to connect to the host via ssh: OpenSSH_9.0p1 Ubuntu-1ubuntu7.1, OpenSSL 3.0.5 5 Jul 2022\r\nCan't open user config file /home/mike/automation/ssh_config: No such file or directory",
The directory exists, it has rw-r--r-- permissions, if I run ssh -F it works fine, but if I manually run the sshpass command it gets the same error, any ideas what might be causing this?