{"id":18925642,"url":"https://github.com/jm1/ansible-role-jm1-kvm-nested-virtualization","last_synced_at":"2026-06-23T22:02:42.364Z","repository":{"id":69767590,"uuid":"330667677","full_name":"JM1/ansible-role-jm1-kvm-nested-virtualization","owner":"JM1","description":"Ansible role to configure KVM nested virtualization for Intel and AMD CPUs","archived":false,"fork":false,"pushed_at":"2022-11-19T13:13:07.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-11T00:42:39.376Z","etag":null,"topics":["ansible","ansible-role","kvm"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JM1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2021-01-18T13:01:34.000Z","updated_at":"2021-10-11T18:40:07.000Z","dependencies_parsed_at":"2023-02-22T12:45:30.003Z","dependency_job_id":null,"html_url":"https://github.com/JM1/ansible-role-jm1-kvm-nested-virtualization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JM1/ansible-role-jm1-kvm-nested-virtualization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JM1%2Fansible-role-jm1-kvm-nested-virtualization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JM1%2Fansible-role-jm1-kvm-nested-virtualization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JM1%2Fansible-role-jm1-kvm-nested-virtualization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JM1%2Fansible-role-jm1-kvm-nested-virtualization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JM1","download_url":"https://codeload.github.com/JM1/ansible-role-jm1-kvm-nested-virtualization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JM1%2Fansible-role-jm1-kvm-nested-virtualization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34708272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"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","ansible-role","kvm"],"created_at":"2024-11-08T11:12:42.712Z","updated_at":"2026-06-23T22:02:42.359Z","avatar_url":"https://github.com/JM1.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Role `jm1.kvm_nested_virtualization`\n\nThis role enables KVM nested virtualization for Intel and AMD CPUs.\n\nIt adds or removes `options kvm_* nested=y` for kernel modules `kvm_intel` and `kvm_amd` in modprobe config file\n`/etc/modprobe.d/kvm-nested-virtualization.conf` (defined with variable `modprobe_conf_path`). When kernel module\noptions have been changed and `reload_module` is true, then it will reload the current kvm kernel module with Ansible\nmodule `community.general.modprobe`.\n\n:warning: **WARNING:**\nThis role will remove and (re)load the `kvm_intel` and `kvm_amd` modules from the Linux kernel to apply changes when\nvariable `reload_module` is set to true. Before executing this role ensure that no virtual machines or other processes\ndepending on these modules are running.\n:warning:\n\nWith `state: present`, this role runs tasks similar to the following shell commands:\n\n```sh\n# Reloading kernel modules and changing their options requires root rights\nsudo -s\n\n# Identify kvm support\nif ! grep -E 'vmx|svm' -q /proc/cpuinfo; then\n    echo \"No virtualization support has been detected\"\nelse\n    if grep -E 'vmx' -q /proc/cpuinfo; then\n        # Detected Intel virtualization\n        kvm_kernel_module=\"kvm_intel\"\n    else\n        # Detected AMD virtualization\n        kvm_kernel_module=\"kvm_amd\"\n    fi\n\n    # Add module options to enable nested virtualization\n    cat \u003c\u003c ____EOF \u003e /etc/modprobe.d/kvm-nested-virtualization.conf\n# 2020-2022 Jakob Meng, \u003cjakobmeng@web.de\u003e\n# Enable KVM nested virtualization for Intel and AMD CPUs\n# Ref.: https://galaxy.ansible.com/jm1/kvm_nested_virtualization\noptions kvm_intel nested=y\noptions kvm_amd nested=1\n____EOF\n\n    # Ensure kernel module is available and loaded\n    modprobe \"$kvm_kernel_module\"\n\n    # Reload kernel module to apply changes\n    if grep -E '^N|0$' -q \"/sys/module/${kvm_kernel_module}/parameters/nested\"; then\n        rmmod \"$kvm_kernel_module\"\n        modprobe \"$kvm_kernel_module\"\n    fi\nfi\n```\n\nWith `state: absent`, this role runs tasks similar to the following shell commands:\n\n```sh\n# Reloading kernel modules and changing their options requires root rights\nsudo -s\n\n# Identify kvm support\nif ! grep -E 'vmx|svm' -q /proc/cpuinfo; then\n    echo \"No virtualization support has been detected\"\nelse\n    if grep -E 'vmx' -q /proc/cpuinfo; then\n        # Detected Intel virtualization\n        kvm_kernel_module=\"kvm_intel\"\n    else\n        # Detected AMD virtualization\n        kvm_kernel_module=\"kvm_amd\"\n    fi\n\n    # Remove module options to enable nested virtualization\n    rm /etc/modprobe.d/kvm-nested-virtualization.conf\n\n    # Ensure kernel module is available and loaded\n    modprobe \"$kvm_kernel_module\"\n\n    # Reload kernel module to apply changes\n    if grep -E '^Y|1$' -q \"/sys/module/${kvm_kernel_module}/parameters/nested\"; then\n        rmmod \"$kvm_kernel_module\"\n        modprobe \"$kvm_kernel_module\"\n    fi\nfi\n```\n\n**Tested OS images**\n- Cloud image of [`Debian 10 (Buster)` \\[`amd64`\\]](https://cdimage.debian.org/images/cloud/buster/daily/)\n- Cloud image of [`Debian 11 (Bullseye)` \\[`amd64`\\]](https://cdimage.debian.org/images/cloud/bullseye/daily/)\n- Cloud image of [`Debian 12 (Bookworm)` \\[`amd64`\\]](https://cdimage.debian.org/images/cloud/bookworm/daily/)\n- Generic cloud image of [`CentOS 7 (Core)` \\[`amd64`\\]](https://cloud.centos.org/centos/7/images/)\n- Generic cloud image of [`CentOS 8 (Core)` \\[`amd64`\\]](https://cloud.centos.org/centos/8/x86_64/images/)\n- Generic cloud image of [`CentOS 9 (Stream)` \\[`amd64`\\]](https://cloud.centos.org/centos/9-stream/x86_64/images/)\n- Ubuntu cloud image of [`Ubuntu 18.04 LTS (Bionic Beaver)` \\[`amd64`\\]](https://cloud-images.ubuntu.com/bionic/current/)\n- Ubuntu cloud image of [`Ubuntu 20.04 LTS (Focal Fossa)` \\[`amd64`\\]](https://cloud-images.ubuntu.com/focal/)\n- Ubuntu cloud image of [`Ubuntu 22.04 LTS (Jammy Jellyfish)` \\[`amd64`\\]](https://cloud-images.ubuntu.com/jammy/)\n\nAvailable on Ansible Galaxy: [jm1.kvm_nested_virtualization](https://galaxy.ansible.com/jm1/kvm_nested_virtualization)\n\nThis role is inspired by [Lukas Bednar's](https://github.com/lukas-bednar)\n[`lukas-bednar.nested_virtualization`](https://github.com/lukas-bednar/ansible-role-nested-virtualization) role.\n\n## Requirements\n\nThis role uses module(s) from collection [`community.general`][galaxy-community-general]. You can fetch this collection\nfrom Ansible Galaxy using the provided [`requirements.yml`](requirements.yml):\n\n```sh\nansible-galaxy collection install --requirements-file requirements.yml\n```\n\n[galaxy-community-general]: https://galaxy.ansible.com/community/general\n\n## Variables\n\n| Name                 | Default value                                    | Required | Description                                                                                                                                     |\n| -------------------- | ------------------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |\n| `modprobe_conf_path` | `/etc/modprobe.d/kvm-nested-virtualization.conf` | no       | Path to modprobe config file. If this file already exists, then it will be overwritten. If `state` is `absent`, then this file will be removed. |\n| `reload_module`      | `yes`                                            | no       | Should the current kernel module be reloaded if configuration has changed. Beware, the module must not be in use, e.g. no VMs must be running   |\n| `state`              | `present`                                        | no       | Should KVM nested virtualization be `present` or `absent`                                                                                       |\n\n## Dependencies\n\nNone.\n\n## Example Playbook\n\n```yml\n- hosts: all\n  roles:\n    - name: Enable KVM nested virtualization for Intel and AMD CPUs\n      role: jm1.kvm_nested_virtualization\n      # Optional: Pass variables to role\n      vars:\n        modprobe_conf_path: '/etc/modprobe.d/kvm-nested-virtualization.conf'\n        reload_module: yes\n        state: present\n```\n\nFor instructions on how to run Ansible playbooks have look at Ansible's\n[Getting Started Guide](https://docs.ansible.com/ansible/latest/network/getting_started/first_playbook.html).\n\n## License\n\nGNU General Public License v3.0 or later\n\nSee [LICENSE.md](LICENSE.md) to see the full text.\n\n## Author\n\nJakob Meng\n@jm1 ([github](https://github.com/jm1), [galaxy](https://galaxy.ansible.com/jm1), [web](http://www.jakobmeng.de))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjm1%2Fansible-role-jm1-kvm-nested-virtualization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjm1%2Fansible-role-jm1-kvm-nested-virtualization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjm1%2Fansible-role-jm1-kvm-nested-virtualization/lists"}