Add roles and variables

This commit is contained in:
lif
2025-10-12 10:13:05 +01:00
parent 78ed25a25a
commit 6368588bce
8 changed files with 150 additions and 78 deletions

View File

@@ -0,0 +1,11 @@
---
# Ansible Galaxy Requirements
# Install with: ansible-galaxy install -r ansible-requirements.yml
# https://github.com/geerlingguy/ansible-role-swap
- name: geerlingguy.swap
version: 1.1.1
# https://github.com/geerlingguy/ansible-role-docker
- name: geerlingguy.docker
version: 7.6.0

View File

@@ -1,2 +1,4 @@
[defaults]
host_key_checking=False
# stdout_callback = minimal
color = true

View File

@@ -0,0 +1,14 @@
---
swap_file_size_mb: 256
swap_file_state: present
swap_file_existing_size_mb: 0
docker_edition: 'ce'
docker_packages:
- "docker-{{ docker_edition }}"
- "docker-{{ docker_edition }}-cli"
- "docker-{{ docker_edition }}-rootless-extras"
docker_packages_state: present
docker_users:
- vagrant

View File

@@ -1,31 +1,49 @@
---
- hosts: all
- hosts: swarm_master
become: true
vars_files:
- group_vars/all.yml
vars:
swap_file_state: present
swap_file_existing_size_mb: 0
roles:
- role: geerlingguy.swap
- role: geerlingguy.docker
- role: common
tasks:
# write hello world to a file in the home directory
- name: write hello
copy:
content: "hello ansible from ansible-manager!"
dest: /home/vagrant/hello2.txt
mode: 0644
become: true
- name: Check memory and swap usage
command: free -m
register: memory_info
changed_when: false
- name: Echo hello
shell: echo 'hello ansible!'
args:
chdir: $HOME
# Echo the contents of the hello.txt file
- name: Echo hello
shell: cat /home/vagrant/hello.txt
args:
chdir: $HOME
# Echo the contents of the hello2.txt file
- name: Echo hello2
shell: cat /home/vagrant/hello2.txt
args:
chdir: $HOME
- name: Ensure Python pip is installed
package:
name: python3-pip
state: present
- name: Ensure Docker SDK for Python is installed
pip:
name: docker>=5.0.0
executable: pip3
- name: Init a new swarm with default parameters
community.docker.docker_swarm:
state: present
- name: Debug all variables
debug:
msg: "swap_file_size_mb: {{ swap_file_size_mb }}, swap_file_state: {{ swap_file_state }}"
- name: Debug Docker variables
debug:
msg: "docker_edition: {{ docker_edition }}, docker_packages: {{ docker_packages }}"
# - name: Debug all host variables
# debug:
# var: hostvars[inventory_hostname]
# - name: Initialize the cluster
# shell: docker swarm init --advertise-addr 192.168.56.10 >> cluster_initialized.txt

View File

@@ -0,0 +1,7 @@
- name: Check memory and swap usage
command: free -m
register: memory_info
changed_when: false
- name: Run the equivalent of "apt-get update" as a separate step
ansible.builtin.apt:
update_cache: yes

16
ansible/swarm-node.yml Normal file
View File

@@ -0,0 +1,16 @@
---
- hosts: swarm_workers
become: true
vars:
roles:
- role: geerlingguy.swap
swap_file_size_mb: 1024
- role: geerlingguy.docker
- role: common
tasks:
- name: Check memory and swap usage
command: free -m
register: memory_info
changed_when: false