├── .circleci └── config.yml ├── .editorconfig ├── .envrc ├── .gitattributes ├── .github ├── CODEOWNERS ├── lock.yml └── workflows │ ├── ci.yml │ └── stale.yml ├── .gitignore ├── .markdownlint-cli2.yaml ├── .mdlrc ├── .overcommit.yml ├── .vscode └── extensions.json ├── .yamllint ├── Berksfile ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dangerfile ├── LICENSE ├── README.md ├── TESTING.md ├── attributes └── default.rb ├── chefignore ├── documentation └── .gitkeep ├── kitchen.dokken.yml ├── kitchen.exec.yml ├── kitchen.global.yml ├── kitchen.yml ├── libraries ├── helpers.rb └── plugin.rb ├── metadata.rb ├── recipes ├── default.rb ├── install_plugins.rb └── uninstall_gem.rb ├── renovate.json ├── resources ├── default.rb └── plugin.rb ├── spec ├── spec_helper.rb └── unit │ └── libraries │ ├── helpers_spec.rb │ └── plugin_spec.rb └── test ├── fixtures ├── cookbooks │ ├── test │ │ ├── metadata.rb │ │ └── recipes │ │ │ ├── default.rb │ │ │ ├── generic.rb │ │ │ ├── genericuninstall.rb │ │ │ └── uninstall.rb │ └── wintest │ │ ├── metadata.rb │ │ ├── recipes │ │ ├── default.rb │ │ ├── windows_location.rb │ │ └── windows_vagrant_plugin.rb │ │ └── resources │ │ └── authorize_service.rb └── mac │ └── mactest.json └── integration ├── default └── inspec │ └── vagrant_spec.rb ├── generic └── inspec │ └── vagrant_spec.rb ├── generic_uninstall └── inspec │ └── vagrant_spec.rb ├── mac └── inspec │ └── vagrant_spec.rb ├── uninstall └── inspec │ └── vagrant_spec.rb ├── windows └── inspec │ └── vagrant_win_spec.rb └── windows_location └── inspec └── vagrant_win_spec.rb /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2.1 3 | orbs: 4 | kitchen: sous-chefs/kitchen@2.1.1 5 | workflows: 6 | danger: 7 | jobs: 8 | - kitchen/danger: 9 | name: danger 10 | context: Danger-Minimal 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root=true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | indent_style = space 13 | indent_size = 2 14 | 15 | # Avoid issues parsing cookbook files later 16 | charset = utf-8 17 | 18 | # Avoid cookstyle warnings 19 | trim_trailing_whitespace = true 20 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use chefworkstation 2 | export KITCHEN_GLOBAL_YAML=kitchen.global.yml 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @sous-chefs/maintainers 2 | -------------------------------------------------------------------------------- /.github/lock.yml: -------------------------------------------------------------------------------- 1 | --- 2 | daysUntilLock: 365 3 | exemptLabels: [] 4 | lockLabel: false 5 | lockComment: > 6 | This thread has been automatically locked since there has not been 7 | any recent activity after it was closed. Please open a new issue for 8 | related bugs. 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | "on": 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | lint-unit: 12 | uses: sous-chefs/.github/.github/workflows/lint-unit.yml@3.1.1 13 | permissions: 14 | actions: write 15 | checks: write 16 | pull-requests: write 17 | statuses: write 18 | issues: write 19 | 20 | integration: 21 | needs: lint-unit 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | os: 26 | - almalinux-8 27 | - centos-7 28 | - centos-stream-8 29 | - debian-10 30 | - debian-11 31 | - rockylinux-8 32 | - ubuntu-1804 33 | - ubuntu-2004 34 | - ubuntu-2204 35 | suite: 36 | - default 37 | - generic 38 | - generic-uninstall 39 | exclude: 40 | - os: centos-7 41 | suite: generic 42 | - os: centos-7 43 | suite: generic-uninstall 44 | fail-fast: false 45 | 46 | steps: 47 | - name: Check out code 48 | uses: actions/checkout@v4 49 | - name: Install Chef 50 | uses: actionshub/chef-install@main 51 | - name: Dokken 52 | uses: actionshub/test-kitchen@main 53 | env: 54 | CHEF_LICENSE: accept-no-persist 55 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml 56 | with: 57 | suite: ${{ matrix.suite }} 58 | os: ${{ matrix.os }} 59 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Mark stale issues and pull requests 3 | 4 | "on": 5 | schedule: [cron: "0 0 * * *"] 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@v9 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | close-issue-message: > 15 | Closing due to inactivity. 16 | If this is still an issue please reopen or open another issue. 17 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 18 | Thanks, Sous-Chefs. 19 | days-before-close: 7 20 | days-before-stale: 365 21 | stale-issue-message: > 22 | Marking stale due to inactivity. 23 | Remove stale label or comment or this will be closed in 7 days. 24 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 25 | Thanks, Sous-Chefs. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | InstalledFiles 4 | pkg 5 | test/tmp 6 | test/version_tmp 7 | tmp 8 | _Store 9 | *~ 10 | *# 11 | .#* 12 | \#*# 13 | *.un~ 14 | *.tmp 15 | *.bk 16 | *.bkup 17 | 18 | # editor files 19 | .idea 20 | .*.sw[a-z] 21 | 22 | # ruby/bundler/rspec files 23 | .ruby-version 24 | .ruby-gemset 25 | .rvmrc 26 | Gemfile.lock 27 | .bundle 28 | *.gem 29 | coverage 30 | spec/reports 31 | 32 | # YARD / rdoc artifacts 33 | .yardoc 34 | _yardoc 35 | doc/ 36 | rdoc 37 | 38 | # chef infra stuff 39 | Berksfile.lock 40 | .kitchen 41 | kitchen.local.yml 42 | vendor/ 43 | .coverage/ 44 | .zero-knife.rb 45 | Policyfile.lock.json 46 | 47 | # vagrant stuff 48 | .vagrant/ 49 | .vagrant.d/ 50 | -------------------------------------------------------------------------------- /.markdownlint-cli2.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | ul-indent: false # MD007 3 | line-length: false # MD013 4 | no-duplicate-heading: false # MD024 5 | reference-links-images: false # MD052 6 | ignores: 7 | - .github/copilot-instructions.md 8 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | rules "~MD013", "~MD024" 2 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | PreCommit: 3 | TrailingWhitespace: 4 | enabled: true 5 | YamlLint: 6 | enabled: true 7 | required_executable: "yamllint" 8 | ChefSpec: 9 | enabled: true 10 | required_executable: "chef" 11 | command: ["chef", "exec", "rspec"] 12 | Cookstyle: 13 | enabled: true 14 | required_executable: "cookstyle" 15 | command: ["cookstyle"] 16 | MarkdownLint: 17 | enabled: false 18 | required_executable: "npx" 19 | command: ["npx", "markdownlint-cli2", "'**/*.md'"] 20 | include: ["**/*.md"] 21 | 22 | CommitMsg: 23 | HardTabs: 24 | enabled: true 25 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "chef-software.chef", 4 | "rebornix.ruby", 5 | "editorconfig.editorconfig", 6 | "DavidAnson.vscode-markdownlint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | line-length: 5 | max: 256 6 | level: warning 7 | document-start: disable 8 | braces: 9 | forbid: false 10 | min-spaces-inside: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: -1 13 | max-spaces-inside-empty: -1 14 | comments: 15 | min-spaces-from-content: 1 16 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'test', path: './test/fixtures/cookbooks/test' 7 | cookbook 'wintest', path: './test/fixtures/cookbooks/wintest' 8 | # cookbook 'build-essential' 9 | end 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## Unreleased 8 | 9 | ## 4.0.18 - *2024-11-18* 10 | 11 | Standardise files with files in sous-chefs/repo-management 12 | 13 | Standardise files with files in sous-chefs/repo-management 14 | 15 | Standardise files with files in sous-chefs/repo-management 16 | 17 | Standardise files with files in sous-chefs/repo-management 18 | 19 | Standardise files with files in sous-chefs/repo-management 20 | 21 | ## 4.0.17 - *2024-05-01* 22 | 23 | ## 4.0.16 - *2024-05-01* 24 | 25 | ## 4.0.15 - *2023-10-31* 26 | 27 | ## 4.0.14 - *2023-09-29* 28 | 29 | ## 4.0.13 - *2023-09-11* 30 | 31 | ## 4.0.12 - *2023-07-10* 32 | 33 | ## 4.0.11 - *2023-05-17* 34 | 35 | ## 4.0.10 - *2023-04-17* 36 | 37 | ## 4.0.9 - *2023-04-07* 38 | 39 | Standardise files with files in sous-chefs/repo-management 40 | 41 | ## 4.0.8 - *2023-04-01* 42 | 43 | ## 4.0.7 - *2023-04-01* 44 | 45 | ## 4.0.6 - *2023-04-01* 46 | 47 | Standardise files with files in sous-chefs/repo-management 48 | 49 | ## 4.0.5 - *2023-03-20* 50 | 51 | Standardise files with files in sous-chefs/repo-management 52 | 53 | ## 4.0.4 - *2023-03-15* 54 | 55 | Standardise files with files in sous-chefs/repo-management 56 | 57 | ## 4.0.3 - *2023-02-24* 58 | 59 | ## 4.0.2 - *2023-02-23* 60 | 61 | Standardise files with files in sous-chefs/repo-management 62 | 63 | ## 4.0.1 - *2023-02-14* 64 | 65 | Standardise files with files in sous-chefs/repo-management 66 | 67 | ## 4.0.0 - *2022-12-23* 68 | 69 | - Update default version to install to 2.3.4 70 | - Logic fixes for installing >= 2.3.0 71 | - CI and Cookstyle fixes 72 | - Update tested platforms 73 | - Standardize helper library and clean it up 74 | - Cleanup and modernize unit tests 75 | - Fix up generic installation 76 | 77 | ## 3.0.2 - *2022-12-13* 78 | 79 | - Standardise files with files in sous-chefs/repo-management 80 | 81 | ## 3.0.1 - *2022-02-17* 82 | 83 | - Standardise files with files in sous-chefs/repo-management 84 | 85 | ## 3.0.0 - *2021-11-01* 86 | 87 | - Enabled `unified_mode` for all resources. 88 | - Dropped compatibility with Chef versions < 15.3. 89 | - Updated Vagrant default version to 2.2.18 (previously was 2.2.4). 90 | 91 | ## 2.0.6 - *2021-08-30* 92 | 93 | - Standardise files with files in sous-chefs/repo-management 94 | 95 | ## 2.0.5 - *2021-06-01* 96 | 97 | - Standardise files with files in sous-chefs/repo-management 98 | 99 | ## 2.0.4 - *2020-12-31* 100 | 101 | - resolved cookstyle error: metadata.rb:31:1 convention: `Layout/TrailingEmptyLines` 102 | 103 | ## 2.0.3 2020-07-14 104 | 105 | - Install plugins in the root user home directory for inspec testing. The plugin location varies depending on environment variables unless explicitly set. 106 | - Test using ubuntu 20.04 107 | - Use build_essential to install vagrant-libvirt 108 | 109 | ## 2.0.2 2020-06-02 110 | 111 | - resolved cookstyle error: test/fixtures/cookbooks/wintest/resources/authorize_service.rb:11:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` 112 | 113 | ## [2.0.1] 2020-02-01 114 | 115 | - Updated tests to work with root user (as is the case on docker machines) 116 | - Style Fixes 117 | - Simplify platform checks 118 | - Migrated to Github Actions for testing 119 | 120 | ## [2.0.0] 2019-10-11 121 | 122 | - Breaking change. Fail if Vagrant install is attempted on an unsupported OS. 123 | - Add. Allow the install of the appimage version of Vagrant. 124 | - Remove. Rubocop.yml doesn'tt need to protect the dangerfile any more. 125 | - Change. Use the latest cookstyle rules 126 | 127 | ## 1.0.0 128 | 129 | - Convert the resources to custom resources 130 | - Add an env property to the plugin resource to allow for setting environment variables. 131 | - Add an example of installing the vagrant-libvirt plugin, this plugin requires specific environment variable settings. See [vagrant-libvirt/issues/891](https://github.com/vagrant-libvirt/vagrant-libvirt/issues/891) 132 | - Add mac test instructions. 133 | - Update the testing documentation 134 | 135 | ## 0.9.1 136 | 137 | - Update the README to describe the new vagrant resource 138 | 139 | ## 0.9.0 140 | 141 | - Create a custom resource to install vagrant. Fix issue #69 142 | 143 | ## 0.8.1 144 | 145 | - Change the source respository name 146 | - Add the authorize_service resource for setting up windows testing 147 | - Use environment variable VAGRANT_HOME as the location to install plugins 148 | 149 | ## 0.8.0 150 | 151 | - Add tests for chef-client 14 152 | - Drop testing for chef-client 12 153 | - Fix the calculation of the plugin directory location 154 | - Fixes for Windows 2012R2: 155 | - The Vagrant installer needs to reboot windows, but the MSI does this in a way that chef can't handle. As an alternative, we make chef interrupt itself and reboot the instance. 156 | - Related to the above, the MSI returns two specific exit codes when it finishes (but not 0...) that chef needs to know about. 157 | - Testing windows requires user 'vagrant' to hold the 'Replace a process level token' and 'Adjust Memory Quotas for a process' permissions. At the moment those setting must be made using the secpol.msc interface. A furtur task is to configure the vagrant user via the test cookbook. 158 | - Vagrant version 1.9.7 suffers from the issue described in #82 (Expected process to exit with [0], but received '-1073741515'). For unknown reasons, this problem is resolved by using 2.0.3 (Perhaps also earlier versions, but they were not tested.) 159 | 160 | ## 0.7.2 161 | 162 | - The package extension for the vagrant mac package changed. 163 | After version 1.9.2 the extension is _x86_64.dmg. 164 | - The package extension for the vagrant windows package changed. 165 | After version 1.9.5 the extension is machinetype.msi. 166 | - Added support for amazon linux 167 | - Make the inspec tests run. Move them to the correct directories. 168 | 169 | ## 0.7.1 170 | 171 | - Fixes for Chef 13 compat 172 | - Install Vagrant 1.9.7 by default 173 | 174 | ## 0.7.0 175 | 176 | - Fix #67: Remove depends constraint on Windows 1.x cookbook. 177 | 178 | ## 0.6.0 179 | 180 | - Install Vagrant 1.8.5 by default 181 | 182 | ## 0.5.0 183 | 184 | - Install Vagrant 1.8.1 by default 185 | - Switch to [InSpec verifier](https://github.com/chef/inspec) for test-kitchen 186 | 187 | ## 0.4.2 - January 7, 2016 188 | 189 | - Fix regression in `fetch_platform_checksums_for_version` method. Release 0.4.1 changed the checksums URL to the new Hashicorp location and introduced a regression. The `fetch_platform_checksums_for_version` method now returns the correct URL. 190 | 191 | Thanks to Jeff Bachtel for the PR. 192 | 193 | ## 0.4.1 - January 6, 2016 194 | 195 | - Hashicorp has moved Vagrant package downloads from bintray.com to hashicorp.com. Download Vagrant packages from new location. 196 | 197 | ## 0.4.0 - December 21, 2015 198 | 199 | - Bump default Vagrant version to 1.7.4 200 | - Cookbook no longer fails during compile phase if is unavailable. You can override `node['vagrant']['url']` and `node['vagrant']['checksum']` if you need to download Vagrant from a different location. 201 | - Fix idempotency when installing Vagrant Windows package. 202 | - Refactor Vagrant::Helpers and add test coverage 203 | - `vagrant_plugin` resource correctly installs vagrant plugins as another user on Windows. 204 | - Refactor LWRP and add unit tests. 205 | 206 | ### Dev environment changes 207 | 208 | - Add ChefSpec [Custom Matchers](https://github.com/sethvargo/chefspec#packaging-custom-matchers) 209 | for `vagrant_plugin`. 210 | - Add Rakefile for testing/style checks. 211 | - Add Travis-CI integration for style and unit tests 212 | - Move vagrant_sha256sum mock to spec/support/shared_context.rb 213 | - Refactor ChefSpec tests - move platform recipe specs into their own spec files 214 | 215 | ## 0.3.1 216 | 217 | - #25, #31 Don't evaluate attributes on unsupported platforms 218 | 219 | ## 0.3.0 220 | 221 | - #11 Custom plugin sources 222 | - #14 Implement user-specific plugin installation 223 | - #20, #21, Fix plugin version detection 224 | - #28 Improve cross platform support 225 | 226 | ## 0.2.2 227 | 228 | - Fix platform_family, `redhat` is not a family, `rhel` is. (#18) 229 | 230 | ## 0.2.0 231 | 232 | - Add `uninstall_gem` recipe to remove vagrant (1.0) gem. 233 | 234 | ## 0.1.1 235 | 236 | - Initial release of vagrant 237 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Guidelines 2 | 3 | This project follows the Chef Community Guidelines 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please refer to 4 | [https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) 5 | -------------------------------------------------------------------------------- /Dangerfile: -------------------------------------------------------------------------------- 1 | # Reference: http://danger.systems/reference.html 2 | 3 | # A pull request summary is required. Add a description of the pull request purpose. 4 | # Changelog must be updated for each pull request that changes code. 5 | # Warnings will be issued for: 6 | # Pull request with more than 400 lines of code changed 7 | # Pull reqest that change more than 5 lines without test changes 8 | # Failures will be issued for: 9 | # Pull request without summary 10 | # Pull requests with code changes without changelog entry 11 | 12 | def code_changes? 13 | code = %w(libraries attributes recipes resources files templates) 14 | code.each do |location| 15 | return true unless git.modified_files.grep(/#{location}/).empty? 16 | end 17 | false 18 | end 19 | 20 | def test_changes? 21 | tests = %w(spec test kitchen.yml kitchen.dokken.yml) 22 | tests.each do |location| 23 | return true unless git.modified_files.grep(/#{location}/).empty? 24 | end 25 | false 26 | end 27 | 28 | failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 29 | 30 | warn 'This is a big Pull Request.' if git.lines_of_code > 400 31 | 32 | warn 'This is a Table Flip.' if git.lines_of_code > 2000 33 | 34 | # Require a CHANGELOG entry for non-test changes. 35 | if !git.modified_files.include?('CHANGELOG.md') && code_changes? 36 | failure 'Please include a CHANGELOG entry.' 37 | end 38 | 39 | # Require Major Minor Patch version labels 40 | unless github.pr_labels.grep /minor|major|patch/i 41 | warn 'Please add a release label to this pull request' 42 | end 43 | 44 | # A sanity check for tests. 45 | if git.lines_of_code > 5 && code_changes? && !test_changes? 46 | warn 'This Pull Request is probably missing tests.' 47 | end 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant Cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/vagrant.svg)](https://supermarket.chef.io/cookbooks/vagrant) 4 | [![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/vagrant/master.svg)](https://circleci.com/gh/sous-chefs/vagrant) 5 | [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) 6 | [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | Installs [Vagrant](https://www.vagrantup.com/) 1.6+ and manages Vagrant plugins via a `vagrant_plugin` resource. 10 | 11 | This cookbook is not intended to be used for vagrant "1.0" (gem install) versions. A recipe is provided for removing the gem, see __Recipes__. 12 | 13 | This cookbook is not supported for installing versions of Vagrant older than 1.6. 14 | 15 | ## Maintainers 16 | 17 | This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). 18 | 19 | ## Requirements 20 | 21 | This cookbook should not be used on platforms that Vagrant itself does not support. 22 | 23 | ## Vagrant Supported Platforms 24 | 25 | Vagrant does not specifically list supported platforms on the project web site. However, the only platforms with [packages provided](https://www.vagrantup.com/downloads.html) are: 26 | 27 | - Mac OS X 28 | - Windows 29 | - Linux (deb-package based platforms, e.g., Debian and Ubuntu) 30 | - Linux (rpm-packaged based platforms, e.g., RHEL and CentOS) 31 | 32 | Other platforms are not supported. This cookbook attempts to exit gracefully in places where unsupported platforms may cause an issue, but it is __strongly recommended__ that this cookbook not be used on an unsupported platform's node run list or used as a dependency for cookbooks used on unsupported platforms. 33 | 34 | ## Tested with Test Kitchen 35 | 36 | - Ubuntu 18.04+ 37 | - CentOS 7+ 38 | - Windows 2016+ 39 | 40 | ## Tested manually 41 | 42 | - OS X 10.9 43 | 44 | May work on other Debian/RHEL family distributions with or without modification. 45 | 46 | This cookbook has [test-kitchen](http://kitchen.ci) support for Windows and Mac OS X, but requires custom Vagrant boxes. 47 | 48 | Because Vagrant is installed as a native system package, Chef must run as a privileged user (e.g., root or Administrator). 49 | 50 | Use of the AppImage version of Vagrant assumes you have set up support for FUSE filesystems. See [FUSE](https://github.com/libfuse/libfuse) 51 | for general explanation of FUSE. The vagrant installation resource does not install or set up FUSE. 52 | 53 | ## Attributes 54 | 55 | ### 'default' recipe. Install the Vagrant Package 56 | 57 | The attributes defined for this cookbook are organized under the 58 | `node['vagrant']` namespace. 59 | 60 | Attribute | Description | Type | Default 61 | ----------|-------------|--------|-------- 62 | ['version'] | Vagrant package version | String | '2.0.3' 63 | ['url'] | Download Vagrant package from this URL | String | Calculated by `vagrant_package_uri` helper method. 64 | ['checksum'] | Vagrant package checksum (SHA256) | String | Calculated by `vagrant_sha256sum` helper method. 65 | ['appimage'] | Use the appimage version | Binary | nil 66 | ['appimage_file'] | Install location | String | nil 67 | 68 | ### 'install_plugins' recipe 69 | 70 | Attributes in the table below are under the `node['vagrant']` namespace. 71 | 72 | Attribute | Description | Type | Default 73 | ----------|-------------|--------|-------- 74 | ['plugins'] | An array of plugins, e.g. `%w(vagrant-aws vagrant-ohai vagrant-omnibus)` | Array | nil 75 | ['plugins'] | If you want to install specific plugin versions, use the second form of the `['plugins']` array, e.g. [ {name: 'vagrant-ohai', version: '0.1.3'}, {name: 'vagrant-aws', version: '0.6.0'} ] | Array of Hashes | nil 76 | 77 | - `node['vagrant']['plugins']` - A array of plugins. The elements in 78 | the array can be a string or a hash. String elements should be the 79 | names of plugins to install. Hash elements should have the name key 80 | for the plugin name. The options version and env keys may be used 81 | to specify the version and any needed environment settings for the 82 | plugin. This form is used by the `vagrant_plugin` resource in the 83 | `install_plugins` recipe. 84 | - `node['vagrant']['user']` - A user that is used to automatically install plugins as for the `node['vagrant']['plugins']` attribute. 85 | - `node['vagrant']['password']` - The password for the user. Used for installing as another user on windows systems. 86 | 87 | ## Resources 88 | 89 | This cookbook includes the: 90 | 91 | - `vagrant` resource, for installing vagrant. 92 | - `vagrant_plugin` resource, for managing vagrant plugins. 93 | 94 | ### vagrant 95 | 96 | #### Actions 97 | 98 | - `:install`: installs vagrant. Platform specific details are here. 99 | 100 | #### Properties 101 | 102 | - `:checksum`: Vagrant package checksum (SHA256) 103 | - `:url`: Download Vagrant package from this URL 104 | - `:version`: Vagrant package version 105 | - `:appimage`: Install the appimage version of vagrant flag 106 | - `:appimage_file`: Install the appimage vagrant file at this location, defaults to /usr/local/bin/vagrant 107 | 108 | #### Examples 109 | 110 | ```ruby 111 | vagrant 'Vagrant' do 112 | version node['vagrant']['version'] 113 | end 114 | 115 | vagrant 'Vagrant from url' do 116 | checksum node['vagrant']['checksum'] 117 | url node['vagrant']['url'] 118 | version node['vagrant']['checksum'] 119 | end 120 | ``` 121 | 122 | ### vagrant_plugin 123 | 124 | #### Actions 125 | 126 | - `:install`: installs the specified plugin. Default. 127 | - `:uninstall`: uninstalls the specified plugin 128 | - `:remove`: uninstalls the specified plugin 129 | 130 | #### Properties 131 | 132 | - `:plugin_name`: name attribute, the name of the plugin, e.g. 133 | "vagrant-omnibus". 134 | - `:version`: version of the plugin to installed, must be specified as a string, e.g., "1.0.2" 135 | - `:env`: plugin environment variable settings, some plugins require specific settings 136 | - `:user`: a user to run plugin installation as. Usually this is for single user systems (like workstations). 137 | - `:sources`: alternate locations to search for plugins. This would commonly 138 | be used if you are hosting your vagrant plugins in a custom gem repo 139 | 140 | #### Examples 141 | 142 | ```ruby 143 | vagrant_plugin 'vagrant-omnibus' 144 | 145 | vagrant_plugin 'vagrant-berkshelf' do 146 | version '1.2.0' 147 | sources ['http://src1.example.com', 'http://src2.example.com'] 148 | end 149 | ``` 150 | 151 | ```ruby 152 | # Install the plugins as the `donuts` user, into ~/donuts/.vagrant.d 153 | # .vagrant.d will be allocated if it does not exist. 154 | # If a specific user, group or mode is desired use a directory resource to 155 | # create the .vagrant.d directory. 156 | vagrant_plugin 'vagrant-aws' do 157 | user 'donuts' 158 | end 159 | ``` 160 | 161 | #### Install the 'vagrant-winrm' plugin for another user. Windows impersonation 162 | 163 | requires a username and password. 164 | 165 | ```ruby 166 | vagrant_plugin 'vagrant-winrm' do 167 | user node['vagrant']['user'] 168 | password node['vagrant']['password'] 169 | end 170 | 171 | # Install a plugin in the /root directory 172 | vagrant_plugin 'vagrant-aws' do 173 | vagrant_home: '/root/.vagrant.d' 174 | end 175 | ``` 176 | 177 | #### ChefSpec Matchers 178 | 179 | Matchers are automatically generated by current versions of ChefSpec. 180 | 181 | Example: 182 | 183 | ```ruby 184 | RSpec.describe 'example::default' do 185 | let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) } 186 | 187 | it 'installs the vagrant-omnibus plugin' do 188 | expect(chef_run).to install_vagrant_plugin('vagrant-omnibus').with( 189 | user: 'my_user' 190 | ) 191 | end 192 | end 193 | ``` 194 | 195 | ## Recipes 196 | 197 | ### default 198 | 199 | The default recipe uses the vagrant resource to install Vagrant. OS specific code is in the install custom resource. If the `node['vagrant']['plugins']` attribute is not empty, it includes the install_plugins recipe to install any required vagrant plugins. 200 | 201 | ### install_plugins 202 | 203 | Iterates over the `node['vagrant']['plugins']` attribute and installs the listed plugins. If that attribute is a hash, it installs the specified plugin version. If the `node['vagrant']['user']` attribute is set, the plugins are installed for only that user. 204 | 205 | ### uninstall_gem 206 | 207 | This recipe will attempt to uninstall the `vagrant` gem with the 208 | `gem_package` and `chef_gem` resources. Meaning, it will use the `gem` 209 | binary in the `PATH` of the shell executing Chef to uninstall, and 210 | then use Chef's built-in RubyGems to uninstall. If you have a 211 | customized Ruby environment, such as with rbenv or rvm (or other), you 212 | may need to manually remove and clean up anything leftover, such as 213 | running `rbenv rehash`. Likewise, if you have multiple copies of the 214 | vagrant gem installed, you'll need to clean up all versions. This 215 | recipe won't support such craziness :-). 216 | 217 | ### Notes about specific plugins 218 | 219 | - vagrant-libvirt. Installing this plugin has required setting environment variables on ubuntu system. Adding env CONFIGURE_ARGS: 'with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib' to the vagrant_plugin resource properties has worked. 220 | 221 | ### Usage 222 | 223 | Set the url and checksum attributes on the node. Do this in a role, or 224 | a "wrapper" cookbook. Or, just set the version and let the magic happen. 225 | 226 | Then include the default recipe on the node's run list. 227 | 228 | To specify plugins for installation in the default recipe, specify an 229 | array for the `node['vagrant']['plugins']` attribute. For example, to 230 | install the `vagrant-omnibus` plugin (any version) and version "1.2.0" 231 | of the `vagrant-berkshelf` plugin: 232 | 233 | ```ruby 234 | node.set['vagrant']['plugins'] = [ 235 | 'vagrant-omnibus', 236 | {name: 'vagrant-berkshelf', version: '1.2.0'} 237 | ] 238 | ``` 239 | 240 | See the attribute tables above. 241 | 242 | ## Contributors 243 | 244 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 245 | 246 | ### Backers 247 | 248 | Thank you to all our backers! 249 | 250 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 251 | 252 | ### Sponsors 253 | 254 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 255 | 256 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 257 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 258 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 259 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 260 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 261 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 262 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 263 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 264 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 265 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 266 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). 4 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Attributes:: default 3 | 4 | # Author:: Joshua Timberman 5 | # Copyright:: (c) 2013-2014, Joshua Timberman 6 | # License:: Apache License, Version 2.0 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | return unless %w(darwin windows linux).include?(node['os']) 21 | 22 | default['vagrant']['version'] = '2.3.4' 23 | 24 | # the URL and checksum are calculated from the package version by helper methods 25 | # in the install resource if you don't override them in a wrapper cookbook 26 | default['vagrant']['url'] = nil 27 | default['vagrant']['checksum'] = nil 28 | default['vagrant']['appimage'] = nil 29 | default['vagrant']['appimage_file'] = nil 30 | 31 | default['vagrant']['plugins'] = [] 32 | default['vagrant']['user'] = nil 33 | # password is required on Windows if you want to install plugins as another user 34 | default['vagrant']['password'] = nil 35 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a Chef Infra Server or Supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | ehthumbs.db 9 | Icon? 10 | nohup.out 11 | Thumbs.db 12 | .envrc 13 | 14 | # EDITORS # 15 | ########### 16 | .#* 17 | .project 18 | .settings 19 | *_flymake 20 | *_flymake.* 21 | *.bak 22 | *.sw[a-z] 23 | *.tmproj 24 | *~ 25 | \#* 26 | REVISION 27 | TAGS* 28 | tmtags 29 | .vscode 30 | .editorconfig 31 | 32 | ## COMPILED ## 33 | ############## 34 | *.class 35 | *.com 36 | *.dll 37 | *.exe 38 | *.o 39 | *.pyc 40 | *.so 41 | */rdoc/ 42 | a.out 43 | mkmf.log 44 | 45 | # Testing # 46 | ########### 47 | .circleci/* 48 | .codeclimate.yml 49 | .delivery/* 50 | .foodcritic 51 | .kitchen* 52 | .mdlrc 53 | .overcommit.yml 54 | .rspec 55 | .rubocop.yml 56 | .travis.yml 57 | .watchr 58 | .yamllint 59 | azure-pipelines.yml 60 | Dangerfile 61 | examples/* 62 | features/* 63 | Guardfile 64 | kitchen*.yml 65 | mlc_config.json 66 | Procfile 67 | Rakefile 68 | spec/* 69 | test/* 70 | 71 | # SCM # 72 | ####### 73 | .git 74 | .gitattributes 75 | .gitconfig 76 | .github/* 77 | .gitignore 78 | .gitkeep 79 | .gitmodules 80 | .svn 81 | */.bzr/* 82 | */.git 83 | */.hg/* 84 | */.svn/* 85 | 86 | # Berkshelf # 87 | ############# 88 | Berksfile 89 | Berksfile.lock 90 | cookbooks/* 91 | tmp 92 | 93 | # Bundler # 94 | ########### 95 | vendor/* 96 | Gemfile 97 | Gemfile.lock 98 | 99 | # Policyfile # 100 | ############## 101 | Policyfile.rb 102 | Policyfile.lock.json 103 | 104 | # Documentation # 105 | ############# 106 | CODE_OF_CONDUCT* 107 | CONTRIBUTING* 108 | documentation/* 109 | TESTING* 110 | UPGRADING* 111 | 112 | # Vagrant # 113 | ########### 114 | .vagrant 115 | Vagrantfile 116 | -------------------------------------------------------------------------------- /documentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/vagrant/18399e52fffb60ffd4bf32e69cea57bf8d27f59d/documentation/.gitkeep -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: { name: dokken } 7 | provisioner: { name: dokken } 8 | 9 | platforms: 10 | - name: almalinux-8 11 | driver: 12 | image: dokken/almalinux-8 13 | pid_one_command: /usr/lib/systemd/systemd 14 | 15 | - name: almalinux-9 16 | driver: 17 | image: dokken/almalinux-9 18 | pid_one_command: /usr/lib/systemd/systemd 19 | 20 | - name: almalinux-10 21 | driver: 22 | image: dokken/almalinux-10 23 | pid_one_command: /usr/lib/systemd/systemd 24 | 25 | - name: amazonlinux-2023 26 | driver: 27 | image: dokken/amazonlinux-2023 28 | pid_one_command: /usr/lib/systemd/systemd 29 | 30 | - name: centos-stream-9 31 | driver: 32 | image: dokken/centos-stream-9 33 | pid_one_command: /usr/lib/systemd/systemd 34 | 35 | - name: centos-stream-10 36 | driver: 37 | image: dokken/centos-stream-10 38 | pid_one_command: /usr/lib/systemd/systemd 39 | 40 | - name: debian-11 41 | driver: 42 | image: dokken/debian-11 43 | pid_one_command: /bin/systemd 44 | 45 | - name: debian-12 46 | driver: 47 | image: dokken/debian-12 48 | pid_one_command: /bin/systemd 49 | 50 | - name: fedora-latest 51 | driver: 52 | image: dokken/fedora-latest 53 | pid_one_command: /usr/lib/systemd/systemd 54 | 55 | - name: opensuse-leap-15 56 | driver: 57 | image: dokken/opensuse-leap-15 58 | pid_one_command: /usr/lib/systemd/systemd 59 | 60 | - name: oraclelinux-8 61 | driver: 62 | image: dokken/oraclelinux-8 63 | pid_one_command: /usr/lib/systemd/systemd 64 | 65 | - name: oraclelinux-9 66 | driver: 67 | image: dokken/oraclelinux-9 68 | pid_one_command: /usr/lib/systemd/systemd 69 | 70 | - name: rockylinux-8 71 | driver: 72 | image: dokken/rockylinux-8 73 | pid_one_command: /usr/lib/systemd/systemd 74 | 75 | - name: rockylinux-9 76 | driver: 77 | image: dokken/rockylinux-9 78 | pid_one_command: /usr/lib/systemd/systemd 79 | 80 | - name: ubuntu-20.04 81 | driver: 82 | image: dokken/ubuntu-20.04 83 | pid_one_command: /bin/systemd 84 | 85 | - name: ubuntu-22.04 86 | driver: 87 | image: dokken/ubuntu-22.04 88 | pid_one_command: /bin/systemd 89 | 90 | - name: ubuntu-24.04 91 | driver: 92 | image: dokken/ubuntu-24.04 93 | pid_one_command: /bin/systemd 94 | -------------------------------------------------------------------------------- /kitchen.exec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: { name: exec } 3 | transport: { name: exec } 4 | 5 | platforms: 6 | - name: macos-latest 7 | - name: windows-latest 8 | -------------------------------------------------------------------------------- /kitchen.global.yml: -------------------------------------------------------------------------------- 1 | --- 2 | provisioner: 3 | name: chef_infra 4 | product_name: chef 5 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 6 | channel: stable 7 | install_strategy: once 8 | chef_license: accept 9 | enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> 10 | multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> 11 | deprecations_as_errors: true 12 | log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> 13 | 14 | verifier: 15 | name: inspec 16 | 17 | platforms: 18 | - name: almalinux-8 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: debian-11 23 | - name: debian-12 24 | - name: fedora-latest 25 | - name: opensuse-leap-15 26 | - name: oraclelinux-8 27 | - name: oraclelinux-9 28 | - name: rockylinux-8 29 | - name: rockylinux-9 30 | - name: ubuntu-20.04 31 | - name: ubuntu-22.04 32 | - name: ubuntu-24.04 33 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_infra 7 | chef_license: accept-no-persist 8 | multiple_converge: 2 9 | enforce_idempotency: true 10 | deprecations_as_errors: true 11 | retry_on_exit_code: 12 | - 35 13 | max_retries: 5 14 | wait_for_retry: 90 15 | 16 | verifier: 17 | name: inspec 18 | 19 | platforms: 20 | - name: almalinux-8 21 | - name: centos-7 22 | - name: centos-stream-8 23 | - name: debian-10 24 | - name: debian-11 25 | - name: rockylinux-8 26 | - name: ubuntu-18.04 27 | - name: ubuntu-20.04 28 | - name: ubuntu-22.04 29 | - name: windows-2016 30 | driver: 31 | gui: false 32 | box: stromweld/windows-2016 33 | customize: 34 | memory: 4096 35 | transport: 36 | name: winrm 37 | elevated: true 38 | - name: windows-2019 39 | driver: 40 | gui: false 41 | box: stromweld/windows-2019 42 | customize: 43 | memory: 4096 44 | transport: 45 | name: winrm 46 | elevated: true 47 | 48 | - name: windows-2022 49 | driver: 50 | gui: false 51 | box: stromweld/windows-2022 52 | customize: 53 | memory: 4096 54 | transport: 55 | name: winrm 56 | elevated: true 57 | 58 | suites: 59 | - name: default 60 | run_list: 61 | - recipe[test] 62 | excludes: 63 | - windows-2016 64 | - windows-2019 65 | - windows-2022 66 | 67 | - name: generic 68 | attributes: 69 | vagrant: 70 | appimage: true 71 | run_list: 72 | - recipe[test::generic] 73 | excludes: 74 | - centos-7 75 | - windows-2016 76 | - windows-2019 77 | - windows-2022 78 | 79 | - name: windows 80 | includes: 81 | - windows-2016 82 | - windows-2019 83 | - windows-2022 84 | run_list: 85 | - recipe[wintest] 86 | 87 | - name: windows_location 88 | run_list: 89 | - recipe[wintest::windows_location] 90 | includes: 91 | - windows-2016 92 | - windows-2019 93 | - windows-2022 94 | 95 | - name: uninstall 96 | run_list: 97 | - recipe[test] 98 | - recipe[test::uninstall] 99 | provisioner: 100 | multiple_converge: 1 101 | enforce_idempotency: false 102 | 103 | - name: generic_uninstall 104 | run_list: 105 | - recipe[test::generic] 106 | - recipe[test::genericuninstall] 107 | attributes: 108 | vagrant: 109 | appimage: true 110 | excludes: 111 | - centos-7 112 | - windows-2016 113 | - windows-2019 114 | - windows-2022 115 | provisioner: 116 | multiple_converge: 1 117 | enforce_idempotency: false 118 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Library:: helpers 3 | 4 | # Author:: Joshua Timberman 5 | # Copyright:: Copyright (c) 2014, Joshua Timberman 6 | # License:: Apache License, Version 2.0 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | require 'uri' 21 | require 'open-uri' 22 | 23 | module Vagrant 24 | module Cookbook 25 | module Helpers 26 | def vagrant_package_uri 27 | "#{vagrant_base_uri}#{package_version}/#{package_name}" 28 | end 29 | 30 | def vagrant_sha256sum 31 | sha256sums = fetch_platform_checksums_for_version 32 | extract_checksum(sha256sums) 33 | end 34 | 35 | private 36 | 37 | def vagrant_base_uri 38 | 'https://releases.hashicorp.com/vagrant/' 39 | end 40 | 41 | def package_name 42 | if @appimage 43 | "vagrant_#{package_version}#{package_extension}" 44 | elsif Gem::Version.new(package_version) >= Gem::Version.new('2.3.0') 45 | separator = platform_family?(%w(rhel suse fedora amazon)) ? '-' : '_' 46 | "vagrant#{separator}#{package_version}#{package_extension}" 47 | else 48 | "vagrant_#{package_version}#{package_extension}" 49 | end 50 | end 51 | 52 | def package_version 53 | @vagrant_version 54 | end 55 | 56 | def package_extension 57 | extension = 58 | case node['platform_family'] 59 | when 'mac_os_x' 60 | mac_os_x_extension 61 | when 'windows' 62 | windows_extension 63 | when 'debian' 64 | deb_extension 65 | when 'rhel', 'suse', 'fedora', 'amazon' 66 | rpm_extension 67 | end 68 | extension = '_linux_amd64.zip' if @appimage 69 | raise "HashiCorp doesn't provide a Vagrant package for the #{node['platform']} platform." if extension.nil? 70 | 71 | extension 72 | end 73 | 74 | def fetch_platform_checksums_for_version 75 | checksums_url = "#{vagrant_base_uri}#{package_version}/vagrant_#{package_version}_SHA256SUMS?direct" 76 | URI.open(checksums_url).readlines 77 | end 78 | 79 | def extract_checksum(sha256sums) 80 | raise "SHA 256 sum not found for the Vagrant package #{package_name}" unless sha256sums.grep(/#{package_name}/)[0].respond_to?(:split) 81 | 82 | sha256sums.grep(/#{package_name}/)[0].split.first 83 | end 84 | 85 | def deb_extension 86 | Gem::Version.new(package_version) < Gem::Version.new('2.3.0') ? '_x86_64.deb' : '-1_amd64.deb' 87 | end 88 | 89 | def rpm_extension 90 | Gem::Version.new(package_version) < Gem::Version.new('2.3.0') ? '_x86_64.rpm' : '-1.x86_64.rpm' 91 | end 92 | 93 | def mac_os_x_extension 94 | if Gem::Version.new(package_version) < Gem::Version.new('2.3.0') 95 | last_using_dmg = Gem::Version.new('1.9.2') 96 | Gem::Version.new(package_version) > last_using_dmg ? '_x86_64.dmg' : '.dmg' 97 | else 98 | '_darwin_amd64.dmg' 99 | end 100 | end 101 | 102 | def windows_extension 103 | last_using_msi = Gem::Version.new('1.9.5') 104 | Gem::Version.new(package_version) > last_using_msi ? "#{windows_machine}.msi" : '.msi' 105 | end 106 | 107 | def windows_machine 108 | if Gem::Version.new(package_version) < Gem::Version.new('2.3.0') 109 | node['kernel']['machine'] == 'x86_64' ? '_x86_64' : '_i686' 110 | else 111 | node['kernel']['machine'] == 'x86_64' ? '_windows_amd64' : '_windows_i686' 112 | end 113 | end 114 | end 115 | end 116 | end 117 | Chef::DSL::Recipe.include ::Vagrant::Cookbook::Helpers 118 | Chef::Resource.include ::Vagrant::Cookbook::Helpers 119 | -------------------------------------------------------------------------------- /libraries/plugin.rb: -------------------------------------------------------------------------------- 1 | require 'chef/mixin/shell_out' 2 | 3 | module Vagrant 4 | class UserNotFoundError < ArgumentError 5 | end 6 | 7 | class Plugin 8 | include Chef::Mixin::ShellOut 9 | 10 | attr_reader :plugin_name, :env, :username, :password 11 | 12 | def windows? 13 | @is_windows 14 | end 15 | 16 | def initialize(plugin_name, is_windows, options = {}) 17 | @plugin_name = plugin_name 18 | @is_windows = is_windows 19 | @env = options.fetch(:env, nil).dup 20 | @username = options.fetch(:username, nil).dup 21 | @password = options.fetch(:password, nil).dup 22 | @vagrant_home = options.fetch(:vagrant_home, nil).dup 23 | end 24 | 25 | # Searches for an installed Vagrant plugin 26 | # @param name [String] name of the plugin to find 27 | # @param options [Hash] { username, password, vagrant_home } 28 | # @return [String] version of installed plugin, e.g. '1.23.34' 29 | def installed_version 30 | begin 31 | list = vagrant_plugin_list 32 | rescue UserNotFoundError 33 | # when a user is not found, they can't possibly have any plugins 34 | return Gem::Version.new('0.0.0') 35 | end 36 | plugin_line = find_plugin_line(list) 37 | plugin_line ? Gem::Version.new(extract_version_from(plugin_line)) : nil 38 | end 39 | 40 | def install(version = nil, sources = []) 41 | vagrant_plugin_install = "vagrant plugin install #{plugin_name}" 42 | vagrant_plugin_install << " --plugin-version #{version}" if version 43 | 44 | sources.each do |source| 45 | vagrant_plugin_install << " --plugin-source #{source}" 46 | end 47 | 48 | execute_cli vagrant_plugin_install 49 | end 50 | 51 | def uninstall 52 | execute_cli "vagrant plugin uninstall #{plugin_name}" 53 | end 54 | 55 | def install?(version) 56 | requested_version = version ? Gem::Version.new(version) : Gem::Version.new('0.0.0') 57 | return true unless installed_version 58 | return false if installed_version >= requested_version 59 | 60 | true 61 | end 62 | 63 | def installed? 64 | installed_version 65 | end 66 | 67 | private 68 | 69 | def vagrant_plugin_list 70 | cmd = execute_cli('vagrant plugin list') 71 | cmd.stdout 72 | end 73 | 74 | def find_plugin_line(plugin_list_output) 75 | lines = plugin_list_output.split(/\R/) 76 | lines.find { |plugin| plugin =~ /#{plugin_name}\s\(/ } 77 | end 78 | 79 | def extract_version_from(plugin_line) 80 | semver = /\s\((\d+\.\d+\.\d+)/ # => '1.12.34' 81 | 82 | version = semver.match(plugin_line) 83 | version[1] unless version.nil? 84 | end 85 | 86 | def execute_cli(command) 87 | cmd_args = {} 88 | cmd_args[:user] = username if username 89 | cmd_args[:password] = password if password 90 | cmd_args[:env] = @env || {} 91 | cmd_args[:env]['VAGRANT_HOME'] = vagrant_home if vagrant_home 92 | shell_out!( 93 | command, 94 | **cmd_args 95 | ) 96 | end 97 | 98 | def vagrant_home 99 | return @vagrant_home if @vagrant_home 100 | 101 | user_home_dir = home_dir 102 | ENV['VAGRANT_HOME'] || ::File.join(user_home_dir, '.vagrant.d') unless user_home_dir.nil? 103 | end 104 | 105 | def home_dir 106 | return Dir.home unless username 107 | 108 | # Dir.home(user) raises ArgumentError: user `user` doesn't exist 109 | # on Windows so we must workaround for now. 110 | if windows? 111 | Dir.exist?("C:/Users/#{username}") ? "C:/Users/#{username}" : Dir.home 112 | else 113 | begin 114 | Dir.home(username) 115 | rescue ArgumentError 116 | raise UserNotFoundError 117 | end 118 | end 119 | end 120 | end 121 | end 122 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | # Copyright:: 2015 Joshua Timterman 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name 'vagrant' 16 | maintainer 'Sous Chefs' 17 | maintainer_email 'help@sous-chefs.org' 18 | license 'Apache-2.0' 19 | description 'Installs Vagrant and provides a vagrant_plugin resource for installing Vagrant plugins.' 20 | source_url 'https://github.com/sous-chefs/vagrant' 21 | issues_url 'https://github.com/sous-chefs/vagrant/issues' 22 | chef_version '>= 15.3' 23 | version '4.0.18' 24 | 25 | supports 'centos' 26 | supports 'debian' 27 | supports 'mac_os_x' 28 | supports 'redhat' 29 | supports 'ubuntu' 30 | supports 'windows' 31 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Recipe:: default 3 | # 4 | # Copyright:: 2013, Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | vagrant 'Vagrant' do 19 | version node['vagrant']['version'] 20 | appimage node['vagrant']['appimage'] 21 | appimage_file node['vagrant']['appimage_file'] 22 | end 23 | 24 | include_recipe "#{cookbook_name}::install_plugins" unless node['vagrant']['plugins'].empty? 25 | -------------------------------------------------------------------------------- /recipes/install_plugins.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Recipe:: install_plugins 3 | 4 | # Copyright:: 2013, Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | node['vagrant']['plugins'].each do |plugin| 19 | if plugin.respond_to?(:keys) 20 | vagrant_plugin plugin['name'] do 21 | env plugin['env'] if plugin['env'] 22 | version plugin['version'] if plugin['version'] 23 | user node['vagrant']['user'] if node['vagrant']['user'] 24 | password node['vagrant']['password'] if node['vagrant']['password'] 25 | end 26 | else 27 | vagrant_plugin plugin do 28 | user node['vagrant']['user'] if node['vagrant']['user'] 29 | password node['vagrant']['password'] if node['vagrant']['password'] 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /recipes/uninstall_gem.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Recipe:: uninstall_gem 3 | 4 | # Copyright:: 2015 Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | gem_package 'vagrant' do 19 | action :remove 20 | end 21 | 22 | chef_gem 'vagrant' do 23 | action :remove 24 | end 25 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "packageRules": [ 5 | { 6 | "groupName": "Actions", 7 | "matchUpdateTypes": ["minor", "patch", "pin"], 8 | "automerge": true, 9 | "addLabels": ["Release: Patch", "Skip: Announcements"] 10 | }, 11 | { 12 | "groupName": "Actions", 13 | "matchUpdateTypes": ["major"], 14 | "automerge": false, 15 | "addLabels": ["Release: Patch", "Skip: Announcements"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /resources/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Resource:: install 3 | # Copyright:: 2018 Sous Chefs 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | unified_mode true 18 | 19 | property :checksum, String 20 | property :url, String 21 | property :version, String 22 | property :appimage, [true, false], default: false 23 | property :appimage_file, String, default: '/usr/local/bin/vagrant' 24 | 25 | action_class do 26 | def debian(pkg_uri, pkg_file, pkg_checksum, pkg_version) 27 | if install? 28 | remote_file pkg_file do 29 | source pkg_uri 30 | checksum pkg_checksum 31 | end 32 | dpkg_package 'vagrant' do 33 | source pkg_file 34 | version pkg_version 35 | end 36 | end 37 | file pkg_file do 38 | action :delete 39 | end 40 | end 41 | 42 | def linux(pkg_uri, pkg_file, pkg_checksum) 43 | if install? 44 | package 'openssh-clients' do 45 | package_name 'openssh-client' if platform_family?('debian') 46 | end 47 | 48 | remote_file pkg_file do 49 | source pkg_uri 50 | checksum pkg_checksum 51 | end 52 | 53 | archive_file pkg_file do 54 | destination ::File.dirname(new_resource.appimage_file) 55 | overwrite :auto 56 | end 57 | end 58 | end 59 | 60 | def mac_os_x(pkg_uri, pkg_checksum) 61 | dmg_package 'Vagrant' do 62 | source pkg_uri 63 | checksum pkg_checksum 64 | type 'pkg' 65 | package_id 'com.vagrant.vagrant' 66 | action :install 67 | end 68 | end 69 | 70 | def rhel(pkg_uri, pkg_file, pkg_checksum) 71 | if install? 72 | remote_file pkg_file do 73 | source pkg_uri 74 | checksum pkg_checksum 75 | end 76 | rpm_package 'vagrant' do 77 | source pkg_file 78 | end 79 | end 80 | file pkg_file do 81 | action :delete 82 | end 83 | end 84 | 85 | def windows(pkg_uri, pkg_checksum, pkg_version) 86 | return unless install? 87 | 88 | windows_package 'Vagrant' do 89 | action :install 90 | version pkg_version 91 | source pkg_uri 92 | checksum pkg_checksum 93 | returns [1641, 3010] 94 | options '/norestart' 95 | # We'll do the restart through chef itself to prevent the cookbook from 96 | # continuing to run while the Vagrant MSI is telling Windows to reboot 97 | notifies :reboot_now, 'reboot[reboot_now]', :immediately 98 | end 99 | reboot 'reboot_now' do 100 | action :nothing 101 | end 102 | end 103 | 104 | def install? 105 | Gem::Version.new(@vagrant_version) > installed_version 106 | end 107 | 108 | def installed_version 109 | begin 110 | query = shell_out('vagrant --version').stdout.chomp 111 | rescue Errno::ENOENT 112 | query = '' 113 | end 114 | md = /^Vagrant\s+(?\d+\.\d+\.\d+)/.match(query) 115 | md ? Gem::Version.new(md[:version]) : Gem::Version.new('0.0.0') 116 | end 117 | end 118 | 119 | action :install do 120 | @vagrant_version = new_resource.version 121 | @appimage = new_resource.appimage 122 | @appimage_file = new_resource.appimage_file 123 | @linux_install_dir = ::File.dirname(new_resource.appimage_file) 124 | vagrant_url = new_resource.url || vagrant_package_uri 125 | vagrant_checksum = new_resource.checksum || vagrant_sha256sum 126 | vagrant_rpm = "#{Chef::Config[:file_cache_path]}/vagrant.rpm" 127 | vagrant_deb = "#{Chef::Config[:file_cache_path]}/vagrant.deb" 128 | vagrant_generic = "#{Chef::Config[:file_cache_path]}/vagrant.zip" 129 | 130 | if @appimage 131 | linux(vagrant_url, vagrant_generic, vagrant_checksum) 132 | 133 | elsif platform_family?('debian') 134 | debian(vagrant_url, vagrant_deb, vagrant_checksum, @vagrant_version) 135 | 136 | elsif platform_family?('rhel', 'amazon', 'fedora', 'suse') 137 | Chef::Log.warn 'SUSE is not specifically supported by Vagrant, going to try anyway as if we were RHEL (rpm install).' if platform_family?('suse') 138 | Chef::Log.warn 'Amazon is not specifically supported by Vagrant, going to try anyway as if we were RHEL (rpm install).' if platform_family?('amazon') 139 | rhel(vagrant_url, vagrant_rpm, vagrant_checksum) 140 | 141 | elsif platform_family?('mac_os_x') 142 | mac_os_x(vagrant_url, vagrant_checksum) 143 | 144 | elsif platform_family?('windows') 145 | windows(vagrant_url, vagrant_checksum, @vagrant_version) 146 | 147 | else 148 | Chef::Log.fatal "Unsupported OS #{node['platform_family']}" 149 | end 150 | end 151 | 152 | action :uninstall do 153 | if new_resource.appimage 154 | @appimage_file = new_resource.appimage_file 155 | FileUtils.rm(@appimage_file) if ::File.exist?(@appimage_file) 156 | else 157 | package 'vagrant' do 158 | action :remove 159 | end 160 | end 161 | end 162 | -------------------------------------------------------------------------------- /resources/plugin.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: vagrant 2 | # Resource:: plugin 3 | 4 | # Copyright:: 2015 Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | unified_mode true 19 | 20 | default_action :install 21 | 22 | property :plugin_name, String, name_property: true 23 | property :version, String 24 | property :env, [Hash, nil], default: nil 25 | property :user, String 26 | property :password, String 27 | property :sources, [String, Array] 28 | property :vagrant_home, String 29 | 30 | action_class do 31 | def plugin 32 | is_windows = platform_family?('windows') 33 | @plugin ||= Vagrant::Plugin.new( 34 | new_resource.plugin_name, 35 | is_windows, 36 | env: new_resource.env, 37 | username: new_resource.user, 38 | password: new_resource.password, 39 | vagrant_home: new_resource.vagrant_home 40 | ) 41 | end 42 | 43 | def uninstall 44 | return unless plugin.installed? 45 | 46 | converge_by("Uninstalling Vagrant plugin: #{new_resource.name}") do 47 | plugin.uninstall 48 | end 49 | end 50 | end 51 | 52 | action :install do 53 | return unless plugin.install?(new_resource.version) 54 | 55 | converge_by("Installing Vagrant plugin: #{new_resource.name} #{new_resource.version}") do 56 | plugin.install(new_resource.version, Array(new_resource.sources)) 57 | end 58 | end 59 | 60 | action :remove do 61 | uninstall 62 | end 63 | 64 | action :uninstall do 65 | uninstall 66 | end 67 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true # Use color in STDOUT 6 | config.formatter = :documentation # Use the specified formatter 7 | config.log_level = :error # Avoid deprecation notice SPAM 8 | end 9 | -------------------------------------------------------------------------------- /spec/unit/libraries/helpers_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require_relative '../../../libraries/helpers' 3 | 4 | RSpec.describe Vagrant::Cookbook::Helpers do 5 | class DummyClass < Chef::Node 6 | include Vagrant::Cookbook::Helpers 7 | end 8 | 9 | let(:platform_family) { 'mac_os_x' } 10 | let(:platform) { 'mac_os_x' } 11 | 12 | subject { DummyClass.new } 13 | 14 | before do 15 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 16 | allow(subject).to receive(:[]).with('platform').and_return(platform) 17 | allow(subject).to receive(:package_version).and_return('1.7.4') 18 | allow(subject).to receive(:fetch_platform_checksums_for_version).and_return(checksums) 19 | end 20 | 21 | let(:checksums) do 22 | [ 23 | '3d2e680cc206ac1d480726052e42e193eabce56ed65fc79b91bc85e4c7d2deb8 vagrant_1.7.4.dmg', 24 | 'a1ca7d99f162e001c826452a724341f421adfaef3e1366ee504b73ad19e3574f vagrant_1.7.4.msi', 25 | '050411ba8b36e322c4ce32990d2539e73a87fabd932f7397d2621986084eda6a vagrant_1.7.4_i686.deb', 26 | 'f83ea56f8d1a37f3fdf24dd4d14bf8d15545ed0e39b4c1c5d4055f3de6eb202d vagrant_1.7.4_i686.rpm', 27 | 'dcd2c2b5d7ae2183d82b8b363979901474ba8d2006410576ada89d7fa7668336 vagrant_1.7.4_x86_64.deb', 28 | 'b0a09f6e6f9fc17b01373ff54d1f5b0dc844394886109ef407a5f1bcfdd4e304 vagrant_1.7.4_x86_64.rpm', 29 | ] 30 | end 31 | 32 | it 'returns the correct Vagrant package URL' do 33 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/1.7.4/vagrant_1.7.4.dmg' 34 | end 35 | 36 | it 'returns the correct SHA256 checksum for the mac_os_x package' do 37 | expect(subject.vagrant_sha256sum).to eq '3d2e680cc206ac1d480726052e42e193eabce56ed65fc79b91bc85e4c7d2deb8' 38 | end 39 | 40 | context 'rhel' do 41 | before do 42 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 43 | allow(subject).to receive(:[]).with('platform').and_return(platform) 44 | end 45 | 46 | let(:platform_family) { 'rhel' } 47 | let(:platform) { 'centos' } 48 | 49 | it 'returns the correct Vagrant package URL' do 50 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/1.7.4/vagrant_1.7.4_x86_64.rpm' 51 | end 52 | 53 | it 'returns the correct SHA256 checksum for the RHEL package' do 54 | expect(subject.vagrant_sha256sum).to eq 'b0a09f6e6f9fc17b01373ff54d1f5b0dc844394886109ef407a5f1bcfdd4e304' 55 | end 56 | end 57 | 58 | context 'debian' do 59 | before do 60 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 61 | allow(subject).to receive(:[]).with('platform').and_return(platform) 62 | end 63 | 64 | let(:platform_family) { 'debian' } 65 | let(:platform) { 'ubuntu' } 66 | 67 | it 'returns the correct Vagrant package URL' do 68 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/1.7.4/vagrant_1.7.4_x86_64.deb' 69 | end 70 | 71 | it 'returns the correct SHA256 checksum for the Debian package' do 72 | expect(subject.vagrant_sha256sum).to eq 'dcd2c2b5d7ae2183d82b8b363979901474ba8d2006410576ada89d7fa7668336' 73 | end 74 | end 75 | 76 | context 'windows 64bit' do 77 | before do 78 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 79 | allow(subject).to receive(:[]).with('platform').and_return(platform) 80 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 81 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 82 | end 83 | 84 | let(:platform_family) { 'windows' } 85 | let(:platform) { 'windows' } 86 | let(:machine) { { 'machine' => 'x86_64' } } 87 | 88 | it 'returns the correct Vagrant package URL' do 89 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/1.7.4/vagrant_1.7.4.msi' 90 | end 91 | 92 | it 'returns the correct SHA256 checksum for the Windows package' do 93 | expect(subject.vagrant_sha256sum).to eq 'a1ca7d99f162e001c826452a724341f421adfaef3e1366ee504b73ad19e3574f' 94 | end 95 | end 96 | 97 | context 'windows 32bit' do 98 | before do 99 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 100 | allow(subject).to receive(:[]).with('platform').and_return(platform) 101 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 102 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 103 | end 104 | 105 | let(:platform_family) { 'windows' } 106 | let(:platform) { 'windows' } 107 | let(:machine) { { 'machine' => 'i686' } } 108 | 109 | it 'returns the correct Vagrant package URL' do 110 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/1.7.4/vagrant_1.7.4.msi' 111 | end 112 | 113 | it 'returns the correct SHA256 checksum for the Windows package' do 114 | expect(subject.vagrant_sha256sum).to eq 'a1ca7d99f162e001c826452a724341f421adfaef3e1366ee504b73ad19e3574f' 115 | end 116 | end 117 | 118 | context 'Packer version 2.3.0' do 119 | before do 120 | allow(subject).to receive(:[]).with(:platform_family).and_return(platform_family) 121 | allow(subject).to receive(:package_version).and_return('2.3.0') 122 | allow(subject).to receive(:fetch_platform_checksums_for_version).and_return(checksums) 123 | end 124 | let(:checksums) do 125 | [ 126 | 'eae2fd66da9ce08901ef12a3b3abc5755ad1aafae736f2d68b8885905d376f89 vagrant-2.3.0-1-x86_64.pkg.tar.zst', 127 | '258b1f54d623595e8af0304ca15cecc6cb368e7452eef3b5a76e88113605fc40 vagrant-2.3.0-1.i686.rpm', 128 | 'bbceb4e93e2a13051e8388de300933839ad02ba515e7e24d1dd966a809796b34 vagrant-2.3.0-1.x86_64.rpm', 129 | '9d5b9a0666e249f0758d00fc6200ebf636dc070f0028239e8e26a62aad90de24 vagrant_2.3.0-1_amd64.deb', 130 | '1aef2489ad6bcd8a4161edc98e55925f516575ac0abcb84bffc183d0b24056bc vagrant_2.3.0-1_i686.deb', 131 | '65a5fee8bcfa4bbd3be444efbcd997110a49f5ccc1fffc4457c0110ab51adecb vagrant_2.3.0_darwin_amd64.dmg', 132 | '6679ea147fefc72121b949a94cc4451a6d6f58c92faf568488a3748b8612e7d0 vagrant_2.3.0_linux_amd64.zip', 133 | '21e5c8791d6d61f355214ac12e5744147cdd7d0e2ce2b24489171573a3daaa86 vagrant_2.3.0_windows_amd64.msi', 134 | '0be88e11085517cae8bb4e636fd77da865ded52bcaab5523ce70379d27713669 vagrant_2.3.0_windows_i686.msi', 135 | ] 136 | end 137 | 138 | it 'returns the correct Vagrant package URL' do 139 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0_darwin_amd64.dmg' 140 | end 141 | 142 | it 'returns the correct SHA256 checksum for the mac_os_x package' do 143 | expect(subject.vagrant_sha256sum).to eq '65a5fee8bcfa4bbd3be444efbcd997110a49f5ccc1fffc4457c0110ab51adecb' 144 | end 145 | 146 | context 'rhel' do 147 | before do 148 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 149 | allow(subject).to receive(:[]).with('platform').and_return(platform) 150 | end 151 | 152 | let(:platform_family) { 'rhel' } 153 | let(:platform) { 'centos' } 154 | 155 | it 'returns the correct Vagrant package URL' do 156 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/2.3.0/vagrant-2.3.0-1.x86_64.rpm' 157 | end 158 | 159 | it 'returns the correct SHA256 checksum for the RHEL package' do 160 | expect(subject.vagrant_sha256sum).to eq 'bbceb4e93e2a13051e8388de300933839ad02ba515e7e24d1dd966a809796b34' 161 | end 162 | end 163 | context 'debian' do 164 | before do 165 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 166 | allow(subject).to receive(:[]).with('platform').and_return(platform) 167 | end 168 | 169 | let(:platform_family) { 'debian' } 170 | let(:platform) { 'ubuntu' } 171 | 172 | it 'returns the correct Vagrant package URL' do 173 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0-1_amd64.deb' 174 | end 175 | 176 | it 'returns the correct SHA256 checksum for the Debian package' do 177 | expect(subject.vagrant_sha256sum).to eq '9d5b9a0666e249f0758d00fc6200ebf636dc070f0028239e8e26a62aad90de24' 178 | end 179 | end 180 | context 'windows 64bit' do 181 | before do 182 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 183 | allow(subject).to receive(:[]).with('platform').and_return(platform) 184 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 185 | end 186 | 187 | let(:platform_family) { 'windows' } 188 | let(:platform) { 'windows' } 189 | let(:machine) { { 'machine' => 'x86_64' } } 190 | 191 | it 'returns the correct Vagrant package URL' do 192 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0_windows_amd64.msi' 193 | end 194 | 195 | it 'returns the correct SHA256 checksum for the Windows package' do 196 | expect(subject.vagrant_sha256sum).to eq '21e5c8791d6d61f355214ac12e5744147cdd7d0e2ce2b24489171573a3daaa86' 197 | end 198 | end 199 | 200 | context 'windows 32bit' do 201 | before do 202 | allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) 203 | allow(subject).to receive(:[]).with('platform').and_return(platform) 204 | allow(subject).to receive(:[]).with('kernel').and_return(machine) 205 | end 206 | 207 | let(:platform_family) { 'windows' } 208 | let(:platform) { 'windows' } 209 | let(:machine) { { 'machine' => 'i686' } } 210 | 211 | it 'returns the correct Vagrant package URL' do 212 | expect(subject.vagrant_package_uri).to eq 'https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0_windows_i686.msi' 213 | end 214 | 215 | it 'returns the correct SHA256 checksum for the Windows package' do 216 | expect(subject.vagrant_sha256sum).to eq '0be88e11085517cae8bb4e636fd77da865ded52bcaab5523ce70379d27713669' 217 | end 218 | end 219 | end 220 | end 221 | -------------------------------------------------------------------------------- /spec/unit/libraries/plugin_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../../libraries/plugin' 2 | 3 | RSpec.describe Vagrant::Plugin do 4 | let(:windows_user) { { username: 'my_user', password: 'my_password' } } 5 | let(:unix_user) { { username: 'my_user' } } 6 | 7 | let(:windows_plugin_list) { "simple-plugin (0.1.0, system)\r\ntwo-digit-minor (1.12.34)\r\nvagrant-foobar (2.3.4)" } 8 | let(:unix_plugin_list) { windows_plugin_list.gsub(/\r\n/, "\n") } 9 | 10 | def plugin_cli_with_vpl_mocked(name, is_windows, options = {}) 11 | cli = Vagrant::Plugin.new(name, is_windows, options) 12 | list = cli.windows? ? windows_plugin_list : unix_plugin_list 13 | allow(cli).to receive(:vagrant_plugin_list).and_return(list) 14 | cli 15 | end 16 | 17 | def windows_cli_with_vpl_mocked(name, options = {}) 18 | plugin_cli_with_vpl_mocked(name, true, options) 19 | end 20 | 21 | def unix_cli_with_vpl_mocked(name, options = {}) 22 | plugin_cli_with_vpl_mocked(name, false, options) 23 | end 24 | 25 | describe '#version' do 26 | context 'On Windows' do 27 | it 'given a non-installed plugin, returns nil' do 28 | version = windows_cli_with_vpl_mocked('non-existent').installed_version 29 | expect(version).to be_nil 30 | end 31 | 32 | it 'given an installed plugin name, returns the version' do 33 | version = windows_cli_with_vpl_mocked('simple-plugin').installed_version 34 | expect(version).to eq Gem::Version.new('0.1.0') 35 | end 36 | 37 | it 'given a cli configured with a plugin that has a 2-digit minor version, returns the version' do 38 | version = windows_cli_with_vpl_mocked('two-digit-minor').installed_version 39 | expect(version).to eq Gem::Version.new('1.12.34') 40 | end 41 | 42 | it 'given a cli configured with a user to impersonate, returns the correct version' do 43 | version = windows_cli_with_vpl_mocked('vagrant-foobar', windows_user).installed_version 44 | expect(version).to eq Gem::Version.new('2.3.4') 45 | end 46 | end 47 | 48 | context 'On Unix' do 49 | it 'given a cli configured with a non-installed plugin, returns nil' do 50 | version = unix_cli_with_vpl_mocked('non-existent').installed_version 51 | expect(version).to be_nil 52 | end 53 | 54 | it 'given a cli configured with a name, returns the version' do 55 | version = unix_cli_with_vpl_mocked('simple-plugin').installed_version 56 | expect(version).to eq Gem::Version.new('0.1.0') 57 | end 58 | end 59 | end 60 | 61 | describe '#install' do 62 | it 'given no version or source, executes vagrant plugin install' do 63 | cli = Vagrant::Plugin.new('simple-plugin', true) 64 | expect(cli).to receive(:execute_cli).with('vagrant plugin install simple-plugin') 65 | cli.install 66 | end 67 | 68 | it 'given a version, executes vagrant plugin install targetting the version' do 69 | cli = Vagrant::Plugin.new('version-plugin', false) 70 | expect(cli).to receive(:execute_cli).with('vagrant plugin install version-plugin --plugin-version 0.1.0') 71 | cli.install('0.1.0') 72 | end 73 | 74 | it 'given a source, executes vagrant plugin install from the source' do 75 | cli = Vagrant::Plugin.new('source-plugin', true) 76 | expect(cli).to receive(:execute_cli).with('vagrant plugin install source-plugin --plugin-source https://in-house.server.com/') 77 | cli.install(nil, ['https://in-house.server.com/']) 78 | end 79 | 80 | it 'given two sources, executes vagrant plugin install with both sources' do 81 | cli = Vagrant::Plugin.new('sources-plugin', false) 82 | expect(cli).to receive(:execute_cli).with('vagrant plugin install sources-plugin --plugin-source https://in-house.server.com/ --plugin-source https://alternate.source.com') 83 | cli.install(nil, ['https://in-house.server.com/', 'https://alternate.source.com']) 84 | end 85 | 86 | it 'given both a version and a source, executes vagrant plugin install with both constraints' do 87 | cli = Vagrant::Plugin.new('version-plugin', true) 88 | expect(cli).to receive(:execute_cli).with('vagrant plugin install version-plugin --plugin-version 0.1.0 --plugin-source https://in-house.server.com/') 89 | cli.install('0.1.0', ['https://in-house.server.com/']) 90 | end 91 | end 92 | 93 | describe '#uninstall' do 94 | it 'executes vagrant plugin uninstall' do 95 | cli = Vagrant::Plugin.new('byebye-plugin', true) 96 | expect(cli).to receive(:execute_cli).with('vagrant plugin uninstall byebye-plugin') 97 | cli.uninstall 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/test/metadata.rb: -------------------------------------------------------------------------------- 1 | # Copyright:: 2015 Joshua Timberman 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name 'test' 16 | maintainer 'Sous Chefs' 17 | maintainer_email 'help@sous-chefs.org' 18 | description 'Test cookbook for the vagrant cookbook' 19 | license 'Apache-2.0' 20 | version '0.1.0' 21 | 22 | depends 'vagrant' 23 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: test 2 | # Test:: default 3 | 4 | # Copyright:: 2015 Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | node.default['vagrant']['plugins'] = %w( 19 | vagrant-ohai 20 | vagrant-vbguest 21 | ) 22 | 23 | node.default['vagrant']['user'] = 'root' 24 | 25 | include_recipe 'vagrant::default' 26 | include_recipe 'vagrant::install_plugins' 27 | 28 | # Install the plugins in the /root directory 29 | %w(vagrant-ohai vagrant-berkshelf vagrant-omnibus vagrant-vbguest).each do |plugin| 30 | vagrant_plugin plugin do 31 | vagrant_home '/root/.vagrant.d' 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/test/recipes/generic.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: test 2 | # Test:: default 3 | 4 | # Copyright:: 2015 Joshua Timberman 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | node.default['vagrant']['plugins'] = %w( 19 | vagrant-ohai 20 | vagrant-vbguest 21 | ) 22 | 23 | package 'libfuse2' if platform_family?('debian') 24 | 25 | include_recipe 'vagrant::default' 26 | include_recipe 'vagrant::install_plugins' 27 | 28 | # Install the plugins in the /root directory 29 | %w(vagrant-ohai vagrant-berkshelf vagrant-omnibus vagrant-vbguest).each do |plugin| 30 | vagrant_plugin plugin do 31 | vagrant_home '/root/.vagrant.d' 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/test/recipes/genericuninstall.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: test 2 | # Test:: uninstall 3 | 4 | # Copyright:: 2019 Sous Chefs 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | vagrant 'uninstall appimage' do 19 | action :uninstall 20 | appimage true 21 | end 22 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/test/recipes/uninstall.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: test 2 | # Test:: uninstall 3 | 4 | # Copyright:: 2019 Sous Chefs 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | vagrant 'Vagrant uninstall' do 19 | action :uninstall 20 | end 21 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/wintest/metadata.rb: -------------------------------------------------------------------------------- 1 | # Copyright:: 2015 Joshua Timberman 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name 'wintest' 16 | maintainer 'Sous Chefs' 17 | maintainer_email 'help@sous-chefs.org' 18 | description 'Test cookbook for the vagrant cookbook' 19 | license 'Apache-2.0' 20 | version '0.1.0' 21 | 22 | depends 'vagrant' 23 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/wintest/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: wintest 2 | # Test:: default 3 | 4 | # Copyright:: 2018 Sous Chefs 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | node.default['vagrant']['plugins'] = %w(vagrant-ohai) 19 | 20 | include_recipe 'wintest::windows_vagrant_plugin' 21 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/wintest/recipes/windows_location.rb: -------------------------------------------------------------------------------- 1 | # Cookbook:: test 2 | # Test:: windows_location 3 | 4 | # Copyright:: 2018 Sous-chefs 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | ENV['VAGRANT_HOME'] = 'C:/Users/altloc' 19 | node.default['vagrant']['plugins'] = %w(vagrant-ohai vagrant-winrm vagrant-omnibus) 20 | 21 | directory 'C:/Users/altloc' do 22 | owner 'vagrant' 23 | rights :full_control, 'Everyone', applies_to_children: true 24 | end 25 | 26 | include_recipe 'vagrant' 27 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/wintest/recipes/windows_vagrant_plugin.rb: -------------------------------------------------------------------------------- 1 | # test installing a plugin as a specified user 2 | 3 | directory 'C:/Users/vagrant/.vagrant.d' do 4 | owner 'vagrant' 5 | end 6 | 7 | authorize_service 'Vagrant token auth' do 8 | service 'SeAssignPrimaryTokenPrivilege' 9 | user 'vagrant' 10 | end 11 | 12 | authorize_service 'Vagrant quota auth' do 13 | service 'SeIncreaseQuotaPrivilege' 14 | user 'vagrant' 15 | end 16 | 17 | include_recipe 'vagrant' 18 | 19 | vagrant_plugin 'vagrant-winrm' do 20 | user 'vagrant' 21 | password 'vagrant' 22 | end 23 | 24 | vagrant_plugin 'vagrant-omnibus' do 25 | end 26 | -------------------------------------------------------------------------------- /test/fixtures/cookbooks/wintest/resources/authorize_service.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Add authorizations so shell_out will work 3 | # Adding attributes will work on the next chef-client run, not the current run 4 | # 5 | # References for setting windows privleges 6 | # https://discourse.chef.io/t/setting-replace-a-process-level-token-windows-permission-mid-chef-run/7420/2 7 | # https://pwrshell.net/attribuer-des-privileges-locaux/ 8 | # https://github.com/chef/chef/blob/7f69ad99a2446e9c70112aa531f68a971a52758f/lib/chef/provider/service/windows.rb#L241-L251 9 | # Took most of the code from chef/lib/chef/provider/service/windows.rb 10 | 11 | unified_mode true 12 | 13 | provides :authorize_service 14 | property :service, String, required: true 15 | property :user, String, required: true 16 | 17 | require 'chef/provider/service/simple' if node['os'] =~ /win/i 18 | require 'chef/win32/error' if node['os'] =~ /win/i 19 | require 'win32/service' if node['os'] =~ /win/i 20 | 21 | action_class do 22 | include Chef::ReservedNames::Win32::API::Error 23 | def grant_service(username, service_name) 24 | begin 25 | Chef::ReservedNames::Win32::Security.add_account_right(username, service_name) 26 | rescue Chef::Exceptions::Win32APIError => err 27 | Chef::Log.fatal "Logon-as-service grant failed with output: #{err}" 28 | raise Chef::Exceptions::Service, "#{service_name} grant failed for #{username}: #{err}" 29 | end 30 | 31 | Chef::Log.info "Grant #{service_name} to user '#{username}' successful." 32 | true 33 | end 34 | end 35 | 36 | action :authorize do 37 | unless Chef::ReservedNames::Win32::Security.get_account_right(new_resource.user).include?(new_resource.service) 38 | converge_by("Add service #{new_resource.service} for user #{new_resource.user}") do 39 | grant_service(new_resource.user, new_resource.service) 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /test/fixtures/mac/mactest.json: -------------------------------------------------------------------------------- 1 | { 2 | "vagrant": { 3 | "plugins": ["vagrant-ohai", "vagrant-vbguest"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/integration/default/inspec/vagrant_spec.rb: -------------------------------------------------------------------------------- 1 | describe command('vagrant --version') do 2 | its('stdout') { should match(/Vagrant 2.3.4/) } 3 | its('stderr') { should eq '' } 4 | end 5 | 6 | describe command("sudo su -c 'cd /root && vagrant plugin list'") do 7 | its('stdout') { should match(/vagrant-ohai/) } 8 | its('stdout') { should match(/vagrant-vbguest/) } 9 | its('exit_status') { should eq 0 } 10 | end 11 | 12 | describe command("sudo su -c 'cd /root && vagrant plugin list'") do 13 | its('stdout') { should match(/vagrant-ohai/) } 14 | its('stdout') { should match(/vagrant-berkshelf/) } 15 | its('stdout') { should match(/vagrant-omnibus/) } 16 | its('exit_status') { should eq 0 } 17 | end 18 | -------------------------------------------------------------------------------- /test/integration/generic/inspec/vagrant_spec.rb: -------------------------------------------------------------------------------- 1 | ENV['HOME'] = '/root' 2 | 3 | describe file('/usr/local/bin/vagrant') do 4 | it { should be_file } 5 | end 6 | 7 | describe command('/usr/local/bin/vagrant --version') do 8 | its('stdout') { should match(/Vagrant 2.3.4/) } 9 | its('stderr') { should eq '' } 10 | end 11 | 12 | describe command("sudo su -c 'cd /root && /usr/local/bin/vagrant plugin list'") do 13 | its('stdout') { should match(/vagrant-ohai/) } 14 | its('stdout') { should match(/vagrant-berkshelf/) } 15 | its('stdout') { should match(/vagrant-omnibus/) } 16 | its('exit_status') { should eq 0 } 17 | end 18 | -------------------------------------------------------------------------------- /test/integration/generic_uninstall/inspec/vagrant_spec.rb: -------------------------------------------------------------------------------- 1 | describe file('/usr/local/bin/vagrant') do 2 | it { should_not exist } 3 | end 4 | -------------------------------------------------------------------------------- /test/integration/mac/inspec/vagrant_spec.rb: -------------------------------------------------------------------------------- 1 | ENV['HOME'] = '/root/' 2 | describe command('vagrant --version') do 3 | its('stdout') { should match(/Vagrant 2.2.18/) } 4 | its('stderr') { should eq '' } 5 | end 6 | 7 | describe command('vagrant plugin list') do 8 | its('stdout') { should match(/vagrant-ohai/) } 9 | its('stdout') { should match(/vagrant-vbguest/) } 10 | its('exit_status') { should eq 0 } 11 | end 12 | -------------------------------------------------------------------------------- /test/integration/uninstall/inspec/vagrant_spec.rb: -------------------------------------------------------------------------------- 1 | describe package 'vagrant' do 2 | it { should_not be_installed } 3 | end 4 | 5 | describe command('vagrant --version') do 6 | its('exit_status') { should eq 127 } 7 | end 8 | -------------------------------------------------------------------------------- /test/integration/windows/inspec/vagrant_win_spec.rb: -------------------------------------------------------------------------------- 1 | describe command('vagrant --version') do 2 | its('stdout') { should match(/Vagrant 2.3.0/) } 3 | its('stderr') { should eq '' } 4 | end 5 | 6 | describe command('vagrant plugin list') do 7 | its('stdout') { should match(/vagrant-ohai/) } 8 | its('exit_status') { should eq 0 } 9 | end 10 | 11 | describe command('vagrant plugin list') do 12 | its('stdout') { should match(/vagrant-winrm/) } 13 | its('stdout') { should match(/vagrant-omnibus/) } 14 | end 15 | -------------------------------------------------------------------------------- /test/integration/windows_location/inspec/vagrant_win_spec.rb: -------------------------------------------------------------------------------- 1 | describe command('vagrant --version') do 2 | its('stdout') { should match(/Vagrant 2.3.0/) } 3 | its('stderr') { should eq '' } 4 | end 5 | 6 | describe file('C:\Users\altloc\plugins.json') do 7 | its('content') { should match(/vagrant-ohai/) } 8 | its('content') { should match(/vagrant-winrm/) } 9 | its('content') { should match(/vagrant-omnibus/) } 10 | end 11 | --------------------------------------------------------------------------------