fix: Initial ansible setup

This commit is contained in:
lif
2025-10-12 08:21:43 +01:00
parent 069ac709e1
commit 78ed25a25a
15 changed files with 124 additions and 1572 deletions

56
vagrant/Vagrantfile vendored Normal file
View File

@@ -0,0 +1,56 @@
nodes = [
{ :hostname => 'ansible-manager', :ip => '192.168.56.9', :ram => 256, :cpus => 1 },
{ :hostname => 'swarm-master-1', :ip => '192.168.56.10', :ram => 256, :cpus => 1 },
# { :hostname => 'swarm-master-2', :ip => '192.168.56.11', :ram => 256, :cpus => 1 },
# { :hostname => 'swarm-worker-1', :ip => '192.168.56.12', :ram => 256, :cpus => 1 },
# { :hostname => 'swarm-worker-2', :ip => '192.168.56.13', :ram => 1024, :cpus => 1 }
]
Vagrant.configure("2") do |config|
# config.ssh.insert_key = false
# config.ssh.forward_agent = true
config.vm.provision "ansible" do |ansible|
ansible.playbook = "setup.yml"
# ansible.inventory_path = "../ansible/inventory"
# ansible.verbose = true
# ansible.limit = "all"
# # ansible.raw_arguments = ["--timeout=60"]
end
nodes.each do |node|
puts "Provisioning node: #{node[:hostname]}"
config.vm.define node[:hostname] do |node_config|
node_config.vm.hostname = node[:hostname]
node_config.vm.box = "debian/bullseye64"
# node_config.vm.box_version = "20250415.336224"
# node_config.ssh.private_key_path = "../keys/access"
# node_config.vm.provision "shell", inline: <<-SHELL
# mkdir -p /home/vagrant/.ssh
# echo '$(cat ../keys/access.pub)' >> /home/vagrant/.ssh/authorized_keys
# chown -R vagrant:vagrant /home/vagrant/.ssh
# chmod 700 /home/vagrant/.ssh
# chmod 600 /home/vagrant/.ssh/authorized_keys
# SHELL
# config.vm.provision "shell" do |s|
# ssh_pub_key = File.readlines("../keys/access.pub").first.strip
# s.inline = <<-SHELL
# echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
# echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
# SHELL
# end
# node_config.vm.network "private_network", ip: node[:ip]
# node_config.vm.provider "virtualbox" do |vb|
# vb.name = node[:hostname]
# vb.memory = node[:ram]
# vb.cpus = node[:cpus]
# end
end
end
# config.vm.define "ansible-manager" do |ansible|
# ansible.vm.provision "file", source: "../ansible", destination: "$HOME"
# ansible.vm.provision "shell", path: "ansible.sh"
# ansible.vm.provision "shell", inline: "echo 'hello ansible!'"
# end
end

17
vagrant/setup.yml Normal file
View File

@@ -0,0 +1,17 @@
---
- hosts: all
become: true
tasks:
# write hello world to a file in the home directory
- name: write hello
copy:
content: "hello ansible!"
dest: /home/vagrant/hello.txt
mode: 0644
become: true
- name: Echo hello
shell: echo 'hello ansible!'
args:
chdir: $HOME