hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.21k stars 4.43k forks source link

Enhancement Request: vagrant provision --provision-with-except #13350

Open AlexKintis opened 7 months ago

AlexKintis commented 7 months ago
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/focal64"

  # Provisioner for web server setup
  config.vm.provision "web_server", type: "shell", inline: <<-SHELL
        # Web server setup commands...
  SHELL

  # Another provisioner for database setup (example)
  config.vm.provision "db_setup", type: "shell", inline: <<-SHELL
    # Database setup commands...
  SHELL

  # Additional provisioners can be added here
  config.vm.provision "cms_setup", type: "shell", inline: <<-SHELL
     # Cms setup commands...
  SHELL
end

Feature request When working on complex Vagrant environments with multiple provisioners, there are scenarios where there is a need to re-provision the environment but wish to exclude one specific provisioner (eg. vagrant provision --provision-with-except cms_setup).

Proposal My proposal is adding a new flag to the vagrant provision command, --provision-with-except, which allows users to run all provisioners except for the ones specified. This would work similarly to the existing --provision-with flag but in reverse. For example, vagrant provision --provision-with-except cms_setup would run all provisioners except the one named 'cms_setup'.

An alternative could be to manually disable the provisioner I don't want to run by commenting it out in the Vagrantfile or using environment variables to conditionally include/exclude provisioners. However, these approaches are less convenient and prone to human error, such as forgetting to uncomment or adjust the environment variables back, leading to inconsistent provisioning states.

This feature would greatly enhance the flexibility and efficiency of the development workflow with Vagrant, especially in complex environments where different provisioners serve distinct roles, some of which might not always be necessary to execute. This functionality would allow developers to save time and resources, focusing only on the required aspects of the provisioning process.