Skip to main content

Vagrantfile generator

Project description

Vagrantgen

Vagrantgen is a simply CLI to generate Vagrantfiles from a standard YAML.

This is a YAML example:

- projectname: cluster1
  provider: virtualbox
  vms:
  - name: vm01
    box: rockylinux/8
    mem: 1024
    cpu: 2

And this the Vagrantfile generated:

Vagrant.configure("2") do |config|
    config.vm.synced_folder ".", "/vagrant", disabled: true

    config.vm.define "cluster1vm01" do |node|
        node.vm.hostname = "cluster1vm01"
        node.vm.box = "rockylinux/8"
        node.vm.provider "virtualbox" do |provider|
            provider.memory = "1024"
            provider.cpus = "2"
        end
    end
end

How use the CLI

If you run vagrantgen -h, then you find the help menu:

$ vagrantgen -h

usage: vagrantgen [-h] {template,vf,ai} ...

Vagrantfile Generator - github.com/aramcap/vagrantgen

positional arguments:
  {template,vf,ai}  Subcommands
    template        Generate template
    vf              Generate Vagrantfile
    ai              Generate ansible-inventory file from "vagrant ssh-config" command

optional arguments:
  -h, --help        show this help message and exit

Any menu has --help command available.

  • vagrantgen template: Generates a template to facilitate the use.
  • vagrantgen vf: Generates a Vagrantfile from a template file.
    • With argument -i you can specify a filename (by default vagrant-template.yaml).
    • With argument -o the output is in stdout.
    • With argument -f the output file is overwriten if exists.
  • vagrantgen ai: Generates a Ansible inventory file from vagrant ssh-config command.
    • With argument -o the output is in stdout.
    • With argument -f the output file is overwriten if exists.

Another examples

- projectname: cluster1
  provider: libvirt # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: rockylinux/8
    mem: 1024
    cpu: 2
    disks:
    - name: disk1.qcow2
      size: 10G
    net:
    - network: private_network
      ip: 192.168.122.100
    provision:
    - provisioner: ansible
      payload: "playbook.yml"
- projectname: cluster1
  provider: docker # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos-ssh

Docker provider not support net tag (ports is optional tag):

- projectname: cluster1
  provider: docker # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos-ssh
    ports:
      - "10023:23"

Example with provision (optional tag):

- projectname: cluster1
  provider: docker # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos-ssh
    provision:
    - provisioner: shell-inline # shell-inline, shell-external, ansible
      payload: "echo Hello > /home/vagrant/hello; chown vagrant:vagrant /home/vagrant/hello"
- projectname: cluster1
  provider: docker # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos-ssh
    provision:
    - provisioner: ansible # shell-inline, shell-external, ansible
      payload: "playbook.yml"

Libvirt or Virtualbox providers not support ports tag:

- projectname: cluster1
  provider: virtualbox # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos/7
    mem: 1024
    cpu: 2

Example with network (optional tag):

- projectname: cluster1
  provider: virtualbox # libvirt or virtualbox or docker
  vms:
  - name: vm01
    box: centos/7
    mem: 1024
    cpu: 2
    disks:
    - name: disk1.vdi
      size: 20 # GBs
    net:
    - network: private_network
      ip: 192.168.122.100
    - network: public_network
      dev: br01
    - network: forwarded_port
      guest: 80
      host: 8080
      host_ip: 127.0.0.1

Colaborate

If do you want to colaborate, you can make a pull-request on https://github.com/aramcap/vagrantgen.

License

GNU AFFERO GENERAL PUBLIC LICENSE version 3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vagrantgen-0.5-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file vagrantgen-0.5-py3-none-any.whl.

File metadata

  • Download URL: vagrantgen-0.5-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.28.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.4

File hashes

Hashes for vagrantgen-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e8100882c82c58d101aef429b2a016d0350c48bde47f614503a60bc740e61559
MD5 082c6f52ddeac52646d2cff894f14c9c
BLAKE2b-256 de80e9644434008f63f4911d76e0d9251594b2e200e407cd0f0d0c9c5c6f8b90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page