mitchellh / vagrant-aws

Use Vagrant to manage your EC2 and VPC instances.
MIT License
2.61k stars 573 forks source link

vagrant provision using aws doesn't update cookbook #385

Open yoshiwaan opened 9 years ago

yoshiwaan commented 9 years ago

Hi,

I'm using vagrant-aws and vagrant-berkshelf for cookbook development on Amazon Linux. I'm stuck at the moment having to vagrant destroy and vagrant up every time I need to update cookbooks on a host at the moment as vagrant provision does not update cookbooks on the instance. Running vagrant reload --provision also does not update the cookbooks.

When running vagrant provision I can see the cookbooks being vendored by the vagrant-berkshelf plug-in and the code updates in the ~/.berkshelf/vagrant-berkshelf/shelves/ directory that matches the instance. The recipe files in /vagrant/recipes on the instance also update for the cookbook that the instance relates to.

The problem is that the cookbooks in /tmp/vagrant-chef don't update. When initially running vagrant up there is a line like this:

Rsyncing folder: /Users/Yoshi/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150507-34066-1lwrog7-default/ => /tmp/vagrant-chef/780cbb74e114f6e9b5e901640b54fe0c/cookbooks

Which does not run when using vagrant provision

yoshiwaan commented 9 years ago

vagrant rsync can be used to manually sync the folders before running vagrant provision. It would be good if this could be called upon reload/provision for instances using the aws provider.

gustavovnicius commented 9 years ago

Hi,

I'm stuck too with this problem... But i'm not destroying every time I need to update my cookbooks (also not using thevagrant-berkshelf plugin). Instead i'm having to delete the synced_folders file and reloading with --provision option.

I think that is a Vagrant problem, not vagrant-aws. Cause i'm having this problem every time I need to start my VM's locally (with Virtualbox).

yoshiwaan commented 9 years ago

You don't need to run reload --provision for synced folders, you can just run vagrant rsync to sync folders.

I think this most probably is a vagrant-aws problem because when running on a local provider like virtualbox both the /vagrant folder and the location of the chef cookbooks for berkshelf (the shelf, usually in ~/.berkshelf/vagrant-berkshelf/shelves) are mounted to the VM. In vagrant-aws these are changed to be synced folders (via rsync) instead of mounts. When running vagrant provision the /vagrant directory is synced but the shelf isn't.

Ideally vagrant-aws would add an rsync to the job queue before running provisioning.

On 19 May 2015 at 17:57, Gustavo Vinícius notifications@github.com wrote:

Hi,

I'm stuck too with this problem... But i'm not destroying every time I need to update my cookbooks (also not using thevagrant-berkshelf plugin). Instead i'm having to delete the synced_folders file and reloading with --provision option.

I think that is a Vagrant problem, not vagrant-aws. Cause i'm having this problem every time I need to start my VM's locally (with Virtualbox).

— Reply to this email directly or view it on GitHub https://github.com/mitchellh/vagrant-aws/issues/385#issuecomment-103709174 .

yoshiwaan commented 9 years ago

Related https://github.com/berkshelf/vagrant-berkshelf/issues/281

Temikus commented 9 years ago

By design. This is the reason this happens: https://github.com/mitchellh/vagrant-aws/pull/347

However, if the owners of this repo want to sync folders before provision, this is a one-line change, just run the SyncedFolders action before Provision:

      def self.action_provision
        Vagrant::Action::Builder.new.tap do |b|
          b.use ConfigValidate
          b.use Call, IsCreated do |env, b2|
            if !env[:result]
              b2.use MessageNotCreated
              next
            end

            b2.use SyncedFolders
            b2.use Provision
          end
        end
      end
yoshiwaan commented 9 years ago

Thanks @Temikus. I'd actually already tried adding b2.use SyncedFolders to the action_provision for vagrant-aws but it produces behavior I don't understand.

With the following (and running vagrant-berkshelf and the chef provisioner):

# This action is called when `vagrant provision` is called.
      def self.action_provision
        Vagrant::Action::Builder.new.tap do |b|
          b.use ConfigValidate
          b.use Call, IsCreated do |env, b2|
            if !env[:result]
              b2.use MessageNotCreated
              next
            end

            b2.use Provision
            b2.use SyncedFolders 
          end
        end
      end

The order of operation goes

If I change to this:

# This action is called when `vagrant provision` is called.
      def self.action_provision
        Vagrant::Action::Builder.new.tap do |b|
          b.use ConfigValidate
          b.use Call, IsCreated do |env, b2|
            if !env[:result]
              b2.use MessageNotCreated
              next
            end

            b2.use SyncedFolders 
            b2.use Provision
          end
        end
      end

Then the order goes:

That's not a typo, putting SyncedFolders first results in the sync happening after chef, putting sync after provision results in the sync happening before chef. I'm not sure why.

In any case, in both instances only the /vagrant directory is synced, not any other synced folders (including the berkshelf shelf for the instance). This is despite the berkshelf directory being listed in .vagrant/machines/default/aws/synced_folders and running vagrant rsync syncing all directories.

This then starts to lead me down the rabbit hole of how SyncedFolders work, whether they differ from what happens when you run vagrant rsync how the berkshelf plugin is synced when vagrant up is run and so on, which maybe I'll get to one day.

jhoblitt commented 8 years ago

347 may need to be reverted as this is is major regression in relied upon behavior, regardless of what the docs have claimed.. Current master seriously breaks the work-flow with the puppet provisioner and related plugins such as vagrant-librarian-puppet. Prior to #347, all that was requires was to run vagrant provision <foo>. Post, you have to run vagrant provision <foo> in order to trigger librarian-puppet and wait through an unneeded puppet run, then run vagrant rsync <foo> to copy the modules over to the box, and then run vagrant provision <foo> again, this time waiting through an unnecessary librarian-puppet update before the "effective" puppet run takes place.

Temikus commented 8 years ago

@jhoblitt Maybe file an upstream bug asking for clarification in the behavior? I can file one myself, but I don't use AWS/puppet much, so it may be tough for me to follow-up on those questions.

yoshiwaan commented 8 years ago

It's not just puppet, vagrant-berkshelf has the same problem. In fact anything that relies on synced folders outside of the vagrant directory won't work