{"id":52086191,"url":"https://github.com/rgl/ansible-hyperv-ubuntu-vm","last_synced_at":"2026-08-04T01:01:18.416Z","repository":{"id":351964940,"uuid":"1213248429","full_name":"rgl/ansible-hyperv-ubuntu-vm","owner":"rgl","description":"This is an example Ansible project that creates a Ubuntu Hyper-V Virtual Machine.","archived":false,"fork":false,"pushed_at":"2026-07-04T06:24:58.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-04T08:19:42.522Z","etag":null,"topics":["ansible","hyper-v","hyperv","ubuntu","windows"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-17T07:27:33.000Z","updated_at":"2026-07-04T06:25:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rgl/ansible-hyperv-ubuntu-vm","commit_stats":null,"previous_names":["rgl/ansible-hyperv-ubuntu-vm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rgl/ansible-hyperv-ubuntu-vm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fansible-hyperv-ubuntu-vm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fansible-hyperv-ubuntu-vm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fansible-hyperv-ubuntu-vm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fansible-hyperv-ubuntu-vm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgl","download_url":"https://codeload.github.com/rgl/ansible-hyperv-ubuntu-vm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fansible-hyperv-ubuntu-vm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36256732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-08-03T02:00:06.975Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","hyper-v","hyperv","ubuntu","windows"],"created_at":"2026-08-04T01:01:17.528Z","updated_at":"2026-08-04T01:01:18.401Z","avatar_url":"https://github.com/rgl.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\n[![Build status](https://github.com/rgl/ansible-hyperv-ubuntu-vm/actions/workflows/build.yml/badge.svg)](https://github.com/rgl/ansible-hyperv-ubuntu-vm/actions/workflows/build.yml)\n\nThis is an example Ansible project that creates a Ubuntu Hyper-V Virtual Machine.\n\nFor a more complete Ansible Playbook see the [rgl/my-ubuntu-ansible-playbooks repository](https://github.com/rgl/my-ubuntu-ansible-playbooks).\n\n# Usage\n\nInstall a Windows machine with Hyper-V, [`wasmtime`](https://github.com/bytecodealliance/wasmtime) and [`hadris-iso-cli-wasm`](https://github.com/rgl/hadris-iso-cli-wasm), like in [rgl/my-windows-ansible-playbooks](https://github.com/rgl/my-windows-ansible-playbooks), to serve as the  Hyper-V environment.\n\nConfigure an External Virtual Switch named `Bridge` in your Hyper-V environment.\n\nInstall the [test/templates/ubuntu-26.04-amd64-vsphere virtual machine template](https://github.com/rgl/ubuntu-vagrant) in your Hyper-V environment.\n\nExecute the following procedure in a Ubuntu machine.\n\nInstall Docker.\n\nOpen the [inventory file](inventory.yml) and modify the virtual machines details to fit your environment.\n\nSet your Hyper-V details:\n\n```bash\ncat \u003esecrets.sh \u003c\u003c'EOF'\nexport VM_HYPERV_HOSTNAME='192.168.8.22'\nexport VM_HYPERV_USERNAME='Administrator'\nexport VM_HYPERV_PASSWORD='vagrant'\nexport VM_HYPERV_TEMPLATE='C:/Users/Administrator/.vagrant.d/boxes/ubuntu-26.04-amd64/0.0.0/hyperv/Virtual Hard Disks/packer-ubuntu-amd64.vhdx'\nexport VM_HYPERV_STORAGE='C:/ProgramData/Microsoft/Windows/Hyper-V/Virtual Machines'\nexport VM_SWITCH='Bridge'\n#export VM_VLAN_MODE='Access'\n#export VM_VLAN_ID='1'\nexport VM_GATEWAY='192.168.8.1'\nexport VM_FIRST_IP='192.168.8.200'\nEOF\nsource secrets.sh\n```\n\nLint the playbooks:\n\n```bash\n./ansible-lint.sh --offline --parseable example.yml || echo 'ERROR linting'\n./ansible-lint.sh --offline --parseable example-destroy.yml || echo 'ERROR linting'\n```\n\nList the inventory:\n\n```bash\n./ansible-inventory.sh --list --yaml\n```\n\nSee the facts about the `hv` machine (the Hyper-V Host):\n\n```bash\n./ansible.sh hv -m ansible.builtin.setup\n```\n\nRun an ad-hoc command in the `hv` machine (the Hyper-V Host):\n\n```bash\n./ansible.sh hv -m win_command -a 'whoami /all'\n./ansible.sh hv -m win_command -a 'cmd /c winrm enumerate winrm/config/listener'\n./ansible.sh hv -m win_command -a 'cmd /c winrm get winrm/config'\n./ansible.sh hv -m win_shell -a 'Get-PSSessionConfiguration'\n```\n\nCreate and configure the `vm1` machine (the Hyper-V Guest) using the [`example.yml` playbook](example.yml):\n\n```bash\n./ansible-playbook.sh --limit=vm1 example.yml | tee ansible-example.log\n```\n\nAccess the `vm1` machine (the Hyper-V Guest):\n\n```bash\nvm1_vars=\"$(ANSIBLE_CALLBACK_RESULT_FORMAT=json ANSIBLE_CALLBACK_FORMAT_PRETTY=false \\\n    ./ansible.sh vm1 -m debug -a 'var=hostvars[inventory_hostname]' \\\n    | grep -oP '(?\u003c=SUCCESS =\u003e )\\{.*\\}')\"\nvm1_user=\"$(jq -r '.[\"hostvars[inventory_hostname]\"].ansible_user' \u003c\u003c\u003c\"$vm1_vars\")\"\nvm1_host=\"$(jq -r '.[\"hostvars[inventory_hostname]\"].ansible_host' \u003c\u003c\u003c\"$vm1_vars\")\"\nssh \"$vm1_user@$vm1_host\"\nsudo -i\nid\nuname -a\nip addr\nsystemctl status\nsystemctl status hv-kvp-daemon.service\nnetworkctl status\ntimedatectl status\ncloud-init schema --system --annotate\ncloud-init status --long --wait\nps -efww --forest\nexit # exit sudo -i\nexit # exit ssh\n```\n\nAccess the `vm1` machine (the Hyper-V Guest) from within the `hv` machine (the Hyper-V Host) using the host Hyper-V VMBus Socket (aka vsock):\n\n```bash\nhv_vars=\"$(ANSIBLE_CALLBACK_RESULT_FORMAT=json ANSIBLE_CALLBACK_FORMAT_PRETTY=false \\\n    ./ansible.sh hv -m debug -a 'var=hostvars[inventory_hostname]' \\\n    | grep -oP '(?\u003c=SUCCESS =\u003e )\\{.*\\}')\"\nhv_user=\"$(jq -r '.[\"hostvars[inventory_hostname]\"].ansible_user' \u003c\u003c\u003c\"$hv_vars\")\"\nhv_host=\"$(jq -r '.[\"hostvars[inventory_hostname]\"].ansible_host' \u003c\u003c\u003c\"$hv_vars\")\"\nssh \"$hv_user@$hv_host\"\npwsh\nhvc list\n# connect using hvc ssh.\n# NB hvc ssh uses a hyper-v vmbus socket which does not use the guest network.\n# NB this is equivalent of using ssh -o ProxyCommand='hvc nc %h %p' vagrant@vm1.\n# NB hvc cannot use an ssh path with spaces.\n$env:HV_SSH_COMMAND='C:\\PROGRA~1\\OpenSSH\\ssh.exe'\nhvc ssh vagrant@vm1\ncat /etc/os-release\nps -efww --forest\nsudo ss -a --vsock --processes\nexit # exit hvc ssh.\nexit # exit hv pwsh\nexit # exit hv ssh\n```\n\nDestroy the `vm1` machine (the Hyper-V Guest) using the [`example-destroy.yml` playbook](example-destroy.yml):\n\n```bash\n./ansible-playbook.sh --limit=vm1 example-destroy.yml | tee ansible-example-destroy.log\n```\n\n# References\n\n* [microsoft.hyperv Ansible Collection](https://galaxy.ansible.com/ui/repo/published/microsoft/hyperv)\n* [microsoft.hyperv Ansible Collection repository](https://github.com/ansible-collections/microsoft.hyperv)\n* [HVTools](https://github.com/michaelmsonne/HVTools)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fansible-hyperv-ubuntu-vm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgl%2Fansible-hyperv-ubuntu-vm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fansible-hyperv-ubuntu-vm/lists"}