Skip to content

Automates the deployment of machines based on your inventory specifications.

License

Notifications You must be signed in to change notification settings

blink-zero/ansible-deploy-vm

Repository files navigation

Ansible Deploy VM (Virtual Machine)

GitHub Release Date

Access the domain/realm version of this playbook here

Very Simple Ansible playbook to automate the creation of virtual machines.

This project creates multiple environment var files to use. If you are only working with one environment only use the 'main.yml' in vars and 'main.yml' in the root directory.

This project was used as a base for blink-zero/ansible-ad-lab

Description

The build consists of both Windows and Linux machines. The amount of VM's deployed is customisable through the inventory file. If you only need windows then ensure that the lin option is deselected and vis versa for linux.

The code can be easily modified to suit specific lab environments by modifying the vars/main.yml file.

Playbook Structure

ansible-deploy-vm
├── tasks
|   ├── vmware_create_windows
|     └── main.yml
|   └── vmware_create_linux
|     └── main.yml
├── vars
|   └── main.yml.example
├── inventory_custom.ini.example
├── main.yml
├── config.sh
├── requirements.txt
└── README.md
  • tasks/: directory containing tasks that will be run by the playbook.
  • vars/: directory to save variable files.
  • inventory_custom.ini.example: example inventory of machines to create.
  • main.yml: main playbook in root folder.
  • config.sh: copies example files (vars/playbook/inventories) into seperate files to edit.
  • requirements.txt: dependancies for playbook to run.
  • README.md: instructions and links related to this playbook.

Getting Started

Dependencies

Running the Playbook

On your Ansible Control Node:

  • Clone this repo
git clone https://github.com/blink-zero/ansible-deploy-vm.git
  • Change dir to cloned dir
cd ansible-ad-vm
  • Install requirements
pip install -r requirements.txt
  • Run config.sh to rename example var files and inventory file
chmod +x config.sh
./config.sh
  • Modify vars/main.yml (See Examples)

  • Modify inventory_custom.ini (See Examples)

  • Run playbook with inventory file

ansible-playbook main.yml -i inventory_custom.ini
  • Enter in passwords when prompted

Extra Environments (Optional Configuration)

If you have multiple environments, as part of the config.sh process, multiple environment files will be created (vars/xxx.yml and environment specific playbooks).

Modify the appropriate vars files according to your environment and run the playbook corresponding to it.

Example

  • After modifying the vars/development.yml file.

Run: ansible-playbook development.yml -i inventory_development.ini

Examples

Executing (Example)

ansible-playbook main.yml -i inventory_custom.ini

vars/main.yml Configuration (Example)

---
vcenter_hostname: "vc.example.com"
vcenter_datacenter: "Datacenter_x"
vcenter_validate_certs: false
vcenter_username: "[email protected]"
timezone: "255"
esxi_host: "172.16.0.32"
vm_disk_datastore: "Datastore_x"
disk_size: 100
vm_hw_scsi: "paravirtual"
vm_state: "poweredon"
vm_net_name: "VM Network"
vm_net_type: "vmxnet3"
netmask: "255.255.255.0"
gateway: "172.16.0.1"
dns1: "172.16.0.1"
dns2: "172.16.0.2"
domain: "somedomain.com"
domain_adminuser: "service_joind"
vm_folder: "Example_Folder"

inventory_custom.ini Configuration (Example) - Full List of Tested OS below

[win]
172.16.0.56 inventory_guest_hostname='2022SERVER01' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='windows-server-2022-datacenter-dexp-v23.01' inventory_vm_guestid='windows9Server64Guest'
; 172.16.0.51 inventory_guest_hostname='LT-2022SERVER02' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='windows-server-2022-datacenter-core-v23.01' inventory_vm_guestid='windows9Server64Guest'
; 172.16.0.52 inventory_guest_hostname='LT-2019SERVER01' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='windows-server-2019-datacenter-dexp-v23.01' inventory_vm_guestid='windows9Server64Guest'
; 172.16.0.53 inventory_guest_hostname='LT-2019SERVER02' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='windows-server-2019-datacenter-core-v23.01' inventory_vm_guestid='windows9Server64Guest'
[lin]
172.16.0.61 inventory_guest_hostname='CO7SERVER01' inventory_guest_vcpu='1' inventory_guest_vram='2048' inventory_template_name='linux-centos-7-v23.01' inventory_vm_guestid='centos64Guest'
; 172.16.0.62 inventory_guest_hostname='LT-UBUSERVER01' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='linux-ubuntu-18.04-lts-v23.01' inventory_vm_guestid='ubuntu64Guest'
; 172.16.0.63 inventory_guest_hostname='LT-UBUSERVER02' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='linux-ubuntu-20.04-lts-v23.01' inventory_vm_guestid='ubuntu64Guest'
; 172.16.0.64 inventory_guest_hostname='LT-UBUSERVER03' inventory_guest_vcpu='2' inventory_guest_vram='4096' inventory_template_name='linux-ubuntu-22.04-lts-v23.01' inventory_vm_guestid='ubuntu64Guest'

Note: Comment out lines with ';' to disable building that machine.

Help

How do I install Ansible?

  • Please refer to the Ansible documentation for install guidance: Ansible Install

Why is Ansible saying X module is missing

  • Run pip install -r requirements.txt before running playbook

Version History

  • v1.0.1
    • Added environment specific files
    • Modified config.sh
  • v1.0.0
    • Initial Release

License

MIT

Authors

Contributing

Feel free to open issues, contribute and submit your Pull Requests.

About

Automates the deployment of machines based on your inventory specifications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages