smdahlen/vagrant-hostmanager — pull request #52 by pbitty (2013-11-30 21:49:57+00:00)
Title: Sync state with hosts file in blocks

Pull request #45 added logic to remove destroyed machines from the hosts file. However, it seems that it only works if you have `include_offline = true`.

When ```include_offline``` is false, the machine being destroyed is not returned by ```get_machines``` in [hosts_file.rb:63](https://github.com/smdahlen/vagrant-hostmanager/blob/3edc923b2286247b55b972cc2f2ba8a8f03fac53/lib/vagrant-hostmanager/hosts_file.rb#L63).

This got me thinking of how to clean up the hosts file without any knowledge of machines and names that we may have put in there in the past.

I'm thinking about the idea of delineating a block in the hosts file that belongs to a specific vagrant environment. To sync with the hosts file, we would only have to replace the whole block instead of replacing specific lines. This way we always push the current machine state, without needing to know about what to remove.

Something like this:
```
127.0.0.1 localhost
...
## vagrant-hostmanager-start id: bf507131-14ba-4c27-805d-f6c67bdd9580
10.0.0.1 machine1 alias1.example.com
10.0.0.2 machine2 alias2.example.com
10.0.0.3 machine3 alias3.example.com
## vagrant-hostmanager-end
```

This would require a way to uniquely identify this block. One way this could be done is to generate a UUID and store it in `env[:local_data_path]`, which is where vagrant keeps state attached to a specific `Vagrantfile`.

@smdahlen @bdcribbs , what do you think of this?