Initial commit: Add Vagrant, Ansible playbook, inventory and README

This commit is contained in:
martin.cholewa
2025-07-08 17:33:01 +02:00
commit 91173b7e34
74 changed files with 2129 additions and 0 deletions

118
README.md Normal file
View File

@@ -0,0 +1,118 @@
# README.md
## 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.
```