Compare commits
4 Commits
7b51ce5e66
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
207cb14e4c | ||
|
|
8844cf3dd0 | ||
|
|
df7a69fc7b | ||
|
|
3ec68c88ce |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,9 +1,16 @@
|
|||||||
# Ignore Vagrant working directory
|
# Ignore Vagrant working directory
|
||||||
.vagrant/
|
.vagrant/
|
||||||
|
|
||||||
|
# Ignore large Vagrant box files and images
|
||||||
|
*.box
|
||||||
|
*.img
|
||||||
|
noble-server-cloudimg-arm64.img
|
||||||
|
ubuntu-*.box
|
||||||
|
|
||||||
# Optional: Ignore other common system files
|
# Optional: Ignore other common system files
|
||||||
*.log
|
*.log
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
|||||||
145
README.md
145
README.md
@@ -1,146 +1,3 @@
|
|||||||
# README.md
|
# README.md
|
||||||
|
|
||||||
## Prerequisity
|
https://chosesoft.eu/index.php/2026/01/23/vagrant-utm-minimal-box/
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
# Add the official HashiCorp tap for the latest Vagrant
|
|
||||||
brew tap hashicorp/tap
|
|
||||||
|
|
||||||
# Install Vagrant (latest version from HashiCorp tap)
|
|
||||||
brew install hashicorp/tap/hashicorp-vagrant
|
|
||||||
|
|
||||||
# Install the Vagrant VMware Utility (required for VMware provider integration)
|
|
||||||
brew install --cask vagrant-vmware-utility
|
|
||||||
|
|
||||||
# Install the Vagrant VMware Desktop plugin
|
|
||||||
vagrant plugin install vagrant-vmware-desktop
|
|
||||||
|
|
||||||
# (Optional) Install Vagrant from Homebrew cask if you prefer the cask version
|
|
||||||
# brew install --cask vagrant
|
|
||||||
|
|
||||||
# Check Vagrant version to verify installation
|
|
||||||
vagrant --version
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
List installed Vagrant plugins to verify plugin installation
|
|
||||||
vagrant plugin list
|
|
||||||
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
/
|
|
||||||
├── Vagrantfile
|
|
||||||
├── vytvor_uzivatele.yml
|
|
||||||
└── hosts
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Vagrantfile** – Defines the virtual machine.
|
|
||||||
- **vytvor_uzivatele.yml** – Ansible playbook for creating a user.
|
|
||||||
- **hosts** – Ansible inventory (used for manual runs).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. Starting the VM with Vagrant
|
|
||||||
|
|
||||||
### First Boot or VM Creation
|
|
||||||
|
|
||||||
```
|
|
||||||
vagrant up
|
|
||||||
```
|
|
||||||
|
|
||||||
- This command downloads the required box (e.g., `bento/ubuntu-22.04`), creates, and starts the VM as defined in your Vagrantfile.
|
|
||||||
- If you have configured Ansible as a provisioner in the Vagrantfile, the playbook will run automatically after the VM is created.
|
|
||||||
|
|
||||||
### Re-running Provisioning
|
|
||||||
|
|
||||||
If you want to re-run provisioning (for example, after editing the playbook):
|
|
||||||
|
|
||||||
```
|
|
||||||
vagrant provision
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. Running Ansible Manually
|
|
||||||
|
|
||||||
If you prefer more control, you can run Ansible manually.
|
|
||||||
|
|
||||||
### Step 1: Start the VM
|
|
||||||
|
|
||||||
```
|
|
||||||
vagrant up
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 2: Get SSH Connection Details
|
|
||||||
|
|
||||||
```
|
|
||||||
vagrant ssh-config kube01
|
|
||||||
```
|
|
||||||
|
|
||||||
- Copy the relevant values into the `hosts` inventory file if they are not already set.
|
|
||||||
|
|
||||||
### Step 3: Run the Ansible Playbook
|
|
||||||
|
|
||||||
```
|
|
||||||
ansible-playbook -i hosts vytvor_uzivatele.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
- This command will execute the tasks defined in the playbook on your VM.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. Example Files
|
|
||||||
|
|
||||||
### Vagrantfile (with Ansible provisioner)
|
|
||||||
|
|
||||||
```
|
|
||||||
Vagrant.configure("2") do |config|
|
|
||||||
config.vm.define "kube01" do |kube01|
|
|
||||||
kube01.vm.box = "bento/ubuntu-22.04"
|
|
||||||
kube01.vm.hostname = "kube01"
|
|
||||||
kube01.vm.provider "vmware_fusion" do |v|
|
|
||||||
v.gui = false
|
|
||||||
v.memory = 2048
|
|
||||||
v.cpus = 2
|
|
||||||
end
|
|
||||||
kube01.vm.provision "ansible" do |ansible|
|
|
||||||
ansible.playbook = "vytvor_uzivatele.yml"
|
|
||||||
ansible.verbose = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
### vytvor_uzivatele.yml
|
|
||||||
|
|
||||||
```
|
|
||||||
---
|
|
||||||
- hosts: all
|
|
||||||
become: yes
|
|
||||||
tasks:
|
|
||||||
- name: Add user "novyuzivatel"
|
|
||||||
user:
|
|
||||||
name: novyuzivatel
|
|
||||||
shell: /bin/bash
|
|
||||||
create_home: yes
|
|
||||||
```
|
|
||||||
|
|
||||||
### hosts (inventory for manual run)
|
|
||||||
|
|
||||||
```
|
|
||||||
[kube]
|
|
||||||
kube01 ansible_host=127.0.0.1 ansible_port=2222 ansible_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/kube01/vmware_fusion/private_key
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Summary
|
|
||||||
|
|
||||||
- **Automatic:** Run `vagrant up` (or `vagrant provision`) and everything will be handled automatically.
|
|
||||||
- **Manual:** First run `vagrant up`, then run `ansible-playbook -i hosts vytvor_uzivatele.yml`.
|
|
||||||
|
|
||||||
This setup allows you to easily manage your VM and automate tasks using both Vagrant and Ansible.
|
|
||||||
```
|
|
||||||
|
|||||||
20
Vagrantfile
vendored
20
Vagrantfile
vendored
@@ -1,20 +0,0 @@
|
|||||||
Vagrant.configure("2") do |config|
|
|
||||||
config.vm.define "kube01" do |kube01|
|
|
||||||
kube01.vm.box = "bento/ubuntu-22.04"
|
|
||||||
kube01.vm.hostname = "kube01"
|
|
||||||
|
|
||||||
# Forward host port 2030 to guest port 22 for SSH access
|
|
||||||
kube01.vm.network "forwarded_port", guest: 22, host: 2030, id: "ssh"
|
|
||||||
|
|
||||||
kube01.vm.provider "vmware_fusion" do |v|
|
|
||||||
v.gui = false
|
|
||||||
v.memory = 2048
|
|
||||||
v.cpus = 2
|
|
||||||
end
|
|
||||||
|
|
||||||
kube01.vm.provision "ansible" do |ansible|
|
|
||||||
ansible.playbook = "ansible/vytvor_uzivatele.yml"
|
|
||||||
ansible.verbose = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[defaults]
|
|
||||||
inventory = hosts
|
|
||||||
remote_user = vagrant
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
[kube]
|
|
||||||
kube01 ansible_host=127.0.0.1 ansible_port=2030 ansible_user=vagrant ansible_ssh_private_key_file=/Users/xchose/chosesoft/Vagrant/.vagrant/machines/kube01/vmware_fusion/private_key
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Install favorite tools (vim, telnet, curl)
|
|
||||||
hosts: all
|
|
||||||
become: yes
|
|
||||||
tasks:
|
|
||||||
- name: Ensure vim, telnet, and curl are installed
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- vim
|
|
||||||
- telnet
|
|
||||||
- curl
|
|
||||||
state: present
|
|
||||||
update_cache: yes
|
|
||||||
register: install_tools_result
|
|
||||||
|
|
||||||
- name: Show install result (full)
|
|
||||||
ansible.builtin.debug:
|
|
||||||
var: install_tools_result
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Update all packages on Ubuntu (interactive)
|
|
||||||
hosts: all
|
|
||||||
become: yes
|
|
||||||
tasks:
|
|
||||||
- name: Update apt cache
|
|
||||||
ansible.builtin.apt:
|
|
||||||
update_cache: yes
|
|
||||||
register: apt_update_result
|
|
||||||
|
|
||||||
- name: Show apt update output
|
|
||||||
ansible.builtin.debug:
|
|
||||||
var: apt_update_result.stdout_lines
|
|
||||||
|
|
||||||
- name: Upgrade all packages to the latest version
|
|
||||||
ansible.builtin.apt:
|
|
||||||
upgrade: dist
|
|
||||||
register: apt_upgrade_result
|
|
||||||
|
|
||||||
- name: Show apt upgrade output
|
|
||||||
ansible.builtin.debug:
|
|
||||||
var: apt_upgrade_result.stdout_lines
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
- import_playbook: update_os.yml
|
|
||||||
- import_playbook: install_tools.yml
|
|
||||||
9
minimalBox/Vagrantfile.arm
Normal file
9
minimalBox/Vagrantfile.arm
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = "ubuntu-arm64-local"
|
||||||
|
|
||||||
|
# UTM provider configuration
|
||||||
|
config.vm.provider "utm" do |utm|
|
||||||
|
utm.memory = 2048 # 2GB RAM
|
||||||
|
utm.cpus = 2 # 2 CPU cores
|
||||||
|
end
|
||||||
|
end
|
||||||
2
minimalBox/ubuntu-arm64-box/Vagrantfile
vendored
Normal file
2
minimalBox/ubuntu-arm64-box/Vagrantfile
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
end
|
||||||
4
minimalBox/ubuntu-arm64-box/metadata.json
Normal file
4
minimalBox/ubuntu-arm64-box/metadata.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"provider": "utm",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user